开发者

Serial port read rate in C#

开发者 https://www.devze.com 2023-02-04 17:31 出处:网络
I\'m developing an application under C# to read some data from a hardware which is connected to a serial port.

I'm developing an application under C# to read some data from a hardware which is connected to a serial port.

Basically, the hardware sends its position 开发者_如何学JAVA(X, Y, Z) and its temperature along with a couple of other decimal values via serial port.

I'd like to be able to have a scan rate as fast as 10 milliseconds; Meaning I'd like to read the temperature, position and other values every 10 milliseconds from the port.

There is an MFC application available with the hardware which is able to read data at this rate. Is it possible to have the same performance in C#? I don't have the hardware available now so I don't know if this is possible using C#.


If you need to send around 20 bytes (as estimations of 6 fields, 3 chars each) every 10 ms then you need at least 16k baud which is not much. Actually I have great doubts that C# is sooo slow to fail handling serial port communication.

If you know serial communication parameters of your hardware then it should be easy to use it from C#. I only know how to use it from Win32 API, you need CreateFile, , SetCommTimeouts, SetCommState and ReadFile calls. It seems that this functions are accessible from C# too.

If you don't know the parameters of this serial port, it may be possible to get them with a serial port sniffer however I'm not sure about that.

0

精彩评论

暂无评论...
验证码 换一张
取 消