简体   繁体   English

检测在哪个串行端口(COM)上连接了USB设备

[英]Detect on which serial port (COM) is connected an usb device

I have to find all USB devices that are connected and detect on which COM port are plugged. 我必须找到所有连接的USB设备,并检测插入哪个COM端口。 Do you have an idea to do this in C# ? 您有使用C#进行此操作的想法吗?

I have currently managed to get the PID and VID of all devices, but I cannot find on which COM ports they are connected... 我目前设法获取了所有设备的PID和VID,但是我找不到它们连接在哪个COM端口上...

Thank you in advance for your help. 预先感谢您的帮助。

I think there is no inherent protocol for finding out this information. 我认为没有固有的协议可以找到这些信息。 Inherently the SerialPort does not know what is on the other side. 本质上, SerialPort不知道另一端是什么。 It will be your job to open the port (which will work irrespective of any device plugged in or not) and try to communicate via the port. 打开端口(无论是否插入任何设备都可以工作),并尝试通过端口进行通信将是您的工作。

If your communication attempt succeeds then you know that there is a device connected. 如果您的通信尝试成功,则说明已连接设备。 Otherwise you can assume (but not know for sure, because the device can decide not to be talkative) that there is no device at this port. 否则,您可以假定(但不确定,因为设备可以决定不说话),此端口上没有设备。

Tip: you can get all port names which this command: 提示:您可以通过以下命令获取所有端口名称:

string []  allPortNames = System.IO.Ports.SerialPort.GetPortNames();

now you can iterate through the names and do you check 现在您可以遍历名称并检查

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

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