问题描述
你好,
我正在尝试使用C#和.NET System.IO.Ports.SerialPort类将2个外部设备的时钟同步到1/10秒.
我发送命令并等待响应.我将获得响应的第一个字节所需的时间除以2,然后向设备发送命令以设置其时钟,同时将延迟添加到计算机时间上.然后,我在另一台设备上重复该过程.然后,我可以对时间的数字读数进行拍照,时钟从不相同,有时相差可达100毫秒.
我打印出了与设备进行通信的详细说明(我发送的内容和时间),所有内容都已签出.所以我的问题是:在接收或发送数据时,SerialPort是否有明显的延迟?我是否获得了数据,但仅在20毫秒后才知道?
PS,我正在检查SerialPort.BytesToRead,而不使用dataReceived事件.
Hello,
I am trying to synchronize the clocks of 2 external devices down to 1/10th of a second using C# and the .NET System.IO.Ports.SerialPort class.
I send a command and wait for a response. I divide the time it takes to get the first byte of the response by 2, and send a command to the device to set its clock with the delay added on to the computer time. I then repeat the process on the other device. I can then take a picture of a digital readout of the time, and the clocks are never the same, sometimes differing up to 100ms.
I printed out a detailed account of the communications (what I sent and when) with the devices, and that all checks out. So my question is: does the SerialPort have a significant delay when receiving or sending data? Did I get data, and then only know about it 20ms later?
PS, I am checking SerialPort.BytesToRead and not using the dataReceived event.
推荐答案
这篇关于SerialPort延迟问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!