如何发现设备是否连接到特定的串行(COM)端口? [英] How can I discover if a device is connected to a specific serial (COM) port?

查看:94
本文介绍了如何发现设备是否连接到特定的串行(COM)端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#的 SerialPort 类发现设备是否已连接到特定的串行(COM)端口?

How can I discover, using C#'s SerialPort class, whether a device is connected to a specific serial (COM) port?

注意:即使没有设备连接到该端口,该类的 Open 方法也会打开该端口.

Note: that class's Open method opens the port even if there is no device connected to the port.

推荐答案

答案取决于设备和电缆.

The answer depends on the device and the cable.

在某些情况下,连接设备时会引发DSR( SerialPort.DsrHolding )甚至CTS( SerialPort.CtsHolding ).

In some cases, DSR (SerialPort.DsrHolding) or even CTS (SerialPort.CtsHolding) will be raised when the device is connected.

但是在某些情况下,您可能只连接了Tx/Rx,唯一的告诉方法是尝试与设备进行通信.

But in some cases you may only have Tx / Rx connected, and the only way to tell is to attempt to communicate with the device.

您需要查看设备及其电缆的文档.

You need to look at the documentation for your device and its cable.

没有适用于任何设备的通用解决方案.

There's no general solution that works for any device.

这篇关于如何发现设备是否连接到特定的串行(COM)端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆