2

I have to find all USB devices that are connected and detect on which COM port are plugged. Do you have an idea to do this in 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...

Thank you in advance for your help.

Euro Micelli
  • 33,285
  • 8
  • 51
  • 70
Gabriel Curinga
  • 305
  • 4
  • 20

1 Answers1

0

I think there is no inherent protocol for finding out this information. Inherently the SerialPort does not know what is on the other side. 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

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76