【发布时间】:2016-02-20 17:31:32
【问题描述】:
我目前正在阅读 Win10 中的串行通信。我正在使用这种方法:
https://ms-iot.github.io/content/en-US/win10/samples/SerialSample.htm
但是,我现在想从另一个视图访问 SerialInput 流。 (主页面除外)。
public byte[] rxbytes = new byte[06];
...
private async Task ReadAsync(CancellationToken cancellationToken)
{
Task<UInt32> loadAsyncTask;
uint ReadBufferLength = 24;
// If task cancellation was requested, comply
cancellationToken.ThrowIfCancellationRequested();
// Set InputStreamOptions to complete the asynchronous read operation when one or more bytes is available
dataReaderObject.InputStreamOptions = InputStreamOptions.Partial;
// Create a task object to wait for data on the serialPort.InputStream
loadAsyncTask = dataReaderObject.LoadAsync(ReadBufferLength).AsTask(cancellationToken);
// Launch the task and wait
UInt32 bytesRead = await loadAsyncTask;
rxbytes= new byte[bytesRead];
dataReaderObject.ReadBytes(rxbytes);
}
如果我想将所有代码写入一个视图,这基本上是完美的。但是我需要访问“rxbytes”数组才能处理传入的数据。
一种选择是:
this.AppFrame.Navigate(typeof(page2), rxbytes);
这种方法是在第二页给我六个空字节。 getter 和 setter 方法也不是一个选项,因为变量不是静态的。
还有其他选择吗?
【问题讨论】:
标签: c# .net windows win-universal-app