[UWP]使用SerialDevice读取速度很慢

编程入门 行业动态 更新时间:2024-10-28 16:18:43
本文介绍了[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读取速度很慢

本文发布于:2023-10-23 00:31:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519208.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:速度很慢   UWP   SerialDevice

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!