恒定字节来。可能会增加时间,以便正确填充缓冲区,但是必须保证接收速度快。如何正确填充缓冲区?在初始和最终符号上显示Posik? 可以设定包装的长度吗?在Java中,它是这样的:packet.getLength()
private async Task ReadAsync(CancellationToken cancellationToken)
{
Task<UInt32> loadAsyncTask;
uint ReadBufferLength = 30;
// If task cancellation was requested, comply
cancellationToken.ThrowIfCancellationRequested();
// Set InputStreamOptions to complete the asynchronous read operation when one or more bytes is available
dataReader.InputStreamOptions = InputStreamOptions.Partial;
// Create a task object to wait for data on the serialPort.InputStream
loadAsyncTask = dataReader.LoadAsync(ReadBufferLength).AsTask(cancellationToken);
// Launch the task and wait
UInt32 bytesRead = await loadAsyncTask;
if (bytesRead > 0)
{
String dataBufferStr = dataReader.ReadString(bytesRead);
}
}