SerialDevice.ReadTimeout不起作用 [英] SerialDevice.ReadTimeout not working
问题描述
我最近查看了Windows IoT核心( 10.0.14393.187)和串行通信Raspberry Pi 3上的USB(内置)。 我遇到的问题是SerialDevice.ReadTimeout似乎不起作用。无论
我提供什么价值,如果没有数据到货,它会永远等待。有没有人有类似的经历,甚至更好地找到了解决方案?如果没有可用数据,使用取消令牌也不会取消读取请求。感觉有一些
坏了。有什么建议吗?
I've recently looked at Windows IoT Core ( 10.0.14393.187 )and serial communication via USB (build in) on a Raspberry Pi 3. The issue I've faced is that SerialDevice.ReadTimeout seems not to work. Regardless what value I provide, if no data arrives it is waiting forever. Has anyone made similar experiences or even better found a solution? Working with a cancellation token also does not cancel a read request in case no data is available. It feels there is something broken. Any advice?
使用 ( var
cts = new
CancellationTokenSource ( TimeSpan 。FromMilliseconds(1000)))
using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1000)))
{
{
bytesRead = 等待 dataReaderObject.LoadAsync(ReadBufferLength).AsTask(cts.Token);
bytesRead = await dataReaderObject.LoadAsync(ReadBufferLength).AsTask(cts.Token);
}
}
mikezill
推荐答案
你好
一个解决方法可能是在一个你可以在一段时间后杀死的新线程中启动它
a workaround could be to start this in a new thread that you can kill after a period of time
这篇关于SerialDevice.ReadTimeout不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!