自动检测并连接到虚拟 COM 端口上的设备

Automatically detecting and connecting to a device on a virtual COM-port

我正在研究使用 Modbus RTU 进行通信的嵌入式设备。单个从设备可以配置不同的波特率、奇偶校验、数据位和停止位。

当我将一个从属设备连接到我的计算机时,我必须知道该设备的确切配置才能与其通信。例如在 C# 中,您将按以下方式打开连接:

SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

是否有 "scanning" 设备的虚拟 COM 端口和确定通信参数的标准方法?只需将我的设备插入 USB 端口并单击即可连接到它,这真的很棒。

Is there a standard way of "scanning" the virtual COM-ports for a device and figuring out the communication parameters?

没有

除非设备特别支持它,否则没有标准的方法来 auto-negotiate 波特率。如果设备确实支持它,则需要将已知的字符序列传输到设备,以便它可以检测到正确的波特率。

鉴于 Modbus 不支持自动波特率,这必须以 device-specific 方式实施,因为它不符合 Modbus 规范。所以你每次都必须设置你的串口设置。