如何从所有可用的系统COM端口识别设备连接的COM端口? [英] How do I recognise the COM port to which a Device is connected out of all available system COM ports?

查看:79
本文介绍了如何从所有可用的系统COM端口识别设备连接的COM端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要知道特定设备(比如Humidity USB发射器)所连接的可用系统com端口的COM端口。

如果连接设备,如何仅连接到该COM端口?请任何正文帮助我编写解决方案或相关链接。

Hi,

I have a requirement to know the COM port out of available system com ports to which a particular device (say Humidity USB transmitter) is connected.
How to connect only to that COM port whenever the device is connected ? Please any body help me with programming solutions or related links .

推荐答案

在您实际尝试与之通信之前,没有一种编程方式可以检测某些设备是否已连接设备。设备可以指定特殊检测协议。如果不是(相信我,大多数此类设备的开发人员都是如此邋o,除了这些硬件的功能有限),检测可能会成为问题。



这里这就是为什么:让我们假设协议假定对发送到端口的一些初始命令做出一些响应。您的通信线程(总是尝试使用单独的线程进行任何类型的通信)尝试读取响应并挂起一段时间。但你怎么知道为什么?设备可能需要更长时间,或者没有连接任何设备。但是要等多少时间?你完全不知道。通常,高效检测不太可行。



也就是说,大多数事情取决于RS-232另一端设备上的设备电缆。我希望我能给你一些想法。查阅文档和/或向客户服务部门询问您的问题,对设备进行一些实验,尝试了解它的行为方式。通常,您可能必须通过某些超时检测设备的存在。这不是很好,但是你会对这些过时的硬件有什么期望呢?



-SA
There is no a programmatic way to detect if some device is connected until you actually try to communicate with the device. The device may specify a special detection protocol or not. If not (believe me, the developers of most such devices are so-oo sloppy, in addition to limited capabilities of such hardware), detection may become problematic.

Here is why: let's assume that the protocol assumes some response to some of your initial commands sent to port. Your communication thread (always try to use a separate thread for any kinds of communications) tries to read the response and hangs for certain time. But how do you know why? The device may need some more time, or no device is connected. But how much time to wait? You don't know exactly. Efficient detection is, in general, not very feasible.

That said, most things depends on the device you have on the device on the other end of your RS-232 cable. I hope I gave you some ideas. Consult the documentation and/or ask customer service your question, experiment a bit with the device, try to learn how it behaves. Generally, you may have to detect the presence of the device by some timeout. This is not nice, but what would you expect from such outdated hardware?

—SA


这篇关于如何从所有可用的系统COM端口识别设备连接的COM端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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