[UWP]使用SerialDevice读取速度很慢 [英] [UWP]Read with SerialDevice is slow

查看:182
本文介绍了[UWP]使用SerialDevice读取速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我尝试将SerialDevice类与UWP应用程序一起使用。问题是读取速度很慢,读取10个字节大约需要5秒钟。写入不会导致缓慢。

I try to use the SerialDevice class with a UWP application. The problem is that reading is very slow, about 5 seconds to read 10 bytes. The writing does not cause slowness.

我尝试使用FTDI和USB CDC / ACM控制器,两者都有同样的问题。我还在Raspberry上使用几台Windows 10机器和Windows 10 IoT。

I tried with FTDI and USB CDC/ACM controller, same problem in both. I also trie on several Windows 10 machines and Windows 10 IoT on Raspberry.

使用SerialPort类的.NET标准中的相同代码工作正常,读取时间不到100毫秒。

The same code in .NET standard with the SerialPort class works fine and less than 100ms for reading.

下面是一个示例代码:

_serialPort = await SerialDevice.FromIdAsync(_deviceId);
_serialPort.BaudRate = _baudRate;
_serialPort.Parity = _parity;
_serialPort.DataBits = _dataBits;
_serialPort.StopBits = _stopBits;
_serialPort.WriteTimeout = TimeSpan.FromMilliseconds(300);
_serialPort.ReadTimeout = TimeSpan.FromMilliseconds(2000);

var toWrite = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
var dataWriter = new DataWriter(_serialPort.OutputStream);
dataWriter.WriteBytes(toWrite);
await dataWriter.StoreAsync(); // < 100ms

var dataReader = new DataReader(_serialPort.InputStream) { InputStreamOptions = InputStreamOptions.Partial };
var numberByteRead = await dataReader.LoadAsync(100); // > 4000ms
var result = new byte[numberByteRead];
dataReader.ReadBytes(result);

推荐答案

你好Y.Zahringer, 



根据您对问题的描述,此问题与串行连接设备更相关,在Iot上存在同样的问题,我将帮助您将案例移至Iot论坛以获得更好的支持。



最好的问候,

Leon Guang
Hi Y.Zahringer, 

Based on your description about your question, this issue more related to Serial connection Device, and there is the same issue on Iot, I will help move your case to Iot forum for better support.

Best Regards,
Leon Guang


这篇关于[UWP]使用SerialDevice读取速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆