简体   繁体   English

C#中的串行端口读取率

[英]Serial port read rate in C#

I'm developing an application under C# to read some data from a hardware which is connected to a serial port. 我正在开发使用C#编写的应用程序,以从连接到串行端口的硬件中读取一些数据。

Basically, the hardware sends its position (X, Y, Z) and its temperature along with a couple of other decimal values via serial port. 基本上,硬件通过串行端口发送其位置(X,Y,Z)和温度以及其他几个十进制值。

I'd like to be able to have a scan rate as fast as 10 milliseconds; 我希望扫描速度可以达到10毫秒; Meaning I'd like to read the temperature, position and other values every 10 milliseconds from the port. 意思是我想每10毫秒从端口读取一次温度,位置和其他值。

There is an MFC application available with the hardware which is able to read data at this rate. 硬件上有一个MFC应用程序,能够以这种速率读取数据。 Is it possible to have the same performance in C#? 在C#中是否可以具有相同的性能? I don't have the hardware available now so I don't know if this is possible using C#. 我现在没有可用的硬件,所以我不知道使用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. 如果您需要每10毫秒发送大约20个字节(估计为6个字段,每个3个字符),那么您至少需要16k波特,这不是很多。 Actually I have great doubts that C# is sooo slow to fail handling serial port communication. 实际上,我非常怀疑C#太慢而无法处理串行端口通信。

If you know serial communication parameters of your hardware then it should be easy to use it from C#. 如果您知道硬件的串行通信参数,则应该可以从C#轻松使用它。 I only know how to use it from Win32 API, you need CreateFile, , SetCommTimeouts, SetCommState and ReadFile calls. 我只知道如何从Win32 API使用它,您需要CreateFile,SetCommTimeouts,SetCommState和ReadFile调用。 It seems that this functions are accessible from C# too. 似乎也可以从C#访问此函数。

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. 如果您不知道此串行端口的参数,则可能可以通过串行端口嗅探器获取它们,但是我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM