我在comms类中使用SerialDataReceivedEventHandler接收数据.我大约每1.5秒轮询一次数据,表单中的计时器发出一个呼叫.我有一个系统计时器,用于测试是否在1秒钟内未收到答复的任何超时-发送和接收数据的时间最长为200毫秒. 每隔一段时间我就会超时.我已经监听了两个设备之间的数据,并使用了端口监视器-延迟发生在C#程序中,大约需要3秒钟才能查看所有返回的数据! 有任何想法吗?我可以在发送接收周围尝试锁"吗?
I am using the SerialDataReceivedEventHandler in a comms class to receive data. I am polling data approx, once every 1.5 secs with a call from a timer on my form. I have a system timer to test for any timeouts if a reply is not received within 1 sec - time to transmit and receive data is 200 ms max. Every so often I get a timeout. I have snooped the data between the 2 devices and used a port monitor - the delay is in the C# program and it is taking approx 3 seconds to see all the returned data! Any ideas? Could I try a ''lock'' around the send receive?
推荐答案只有在有多个人试图与SerialPort通信时,才需要锁.目的.如果这样做,我建议您锁定它,因为我怀疑您的通讯会打扰您. 我对您对系统设置的解释不是100%清楚,但是问题可能出在您的轮询方面.如果恰好在轮询后才发送数据,则可能会超时.我会看看提高轮询率是否会改变系统的行为. You''d only need a lock if you have multiple people trying to communicate with the SerialPort object. If you do, I would recommend locking it because I doubt your communications would allow for an interruption. I''m not 100% clear on your explaination of the system setup, but the issue may be on your polling side. If you just so happen to have data sent JUST after a poll, you''ll potentially hit your timeout. I''d see if increasing your polling rate changes your system''s behavior.
更多推荐
SerialPort类
发布评论