SerialPort类

编程入门 行业动态 更新时间:2024-10-26 06:33:20
本文介绍了SerialPort类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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类

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

发布评论

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

>www.elefans.com

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