Click here to Skip to main content
14,695,085 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,
I have a system connect to PC through USB. I am writing the software that has "Connect" button which allows user to connect to that specific USB port. My solution is
1. Scan all available COM ports
2. Send a specific message to each COM port and if the system echo back another specific message that match, the software will connect to that COM port.

However, the problem is some COM ports are already open and in use. So when the software try to OPEN that COM port (which is not my USB), it will be an error. So I would like to scan all the USB ports, with each specific name (my USB port names: TUSB3410 Device, under Device Management). So the job now just connect to that specific USB device name.

How can I get all the USB device name?

Thank you, :)
Updated 11-Oct-20 5:59am


Are you talking about USB or COM port emulator? It sounds like you are talking about a USB that connets as a COM port emulator.

If that is the case, you can use the following method to get the list of names of com port devices.


you can then iterate through the list and find the one you are looking for using a forloop statement.

Hope it helps.

Dave :)
Yes, I am talking about a USB that connects as a COM port. And yes, I do a SerialPort.GetPortNames() to get the COMx name, and connect to that specific USB. But I am facing the problem, let's say the PC I connect the USB has the following COM (in device manager):

1. COM1: Communication Port
2. COM3: Logitech mouse (for example)
3. COM4: other USB to COM port device
5. COM5: TUSB3410 device (my USB)

I iterate the loop, in each loop I do:
1. assign the current port to a Port_temp
2. check if Port_temp is already open? If it is open, it is not the one. It is on the other hand is in use.
3. if it is not open, try open Port_temp
4. send a message
5. receive a message from the MCU
6. check the message from the MCU, if the message matches with some predefined message. Assign the Port_temp to SerialPort and connect to those.

I was successful to connect to the COM5 after doing the loop. However, when I ran the software to other computer(assume they have the same list port above) , it faced the problem that it can open COM3. I do not know why there is a problem, because before opening a port on step 3, I checked if the port was opened or not on step 2.

So that is the reason whey I would like to get the device name of the USB,i.e. Communication Port, TUSB3410 device,etc. So I can connect to specific port with the unique name. Or get the VID/PID is good too. Are there anyway I can get those information about each COM port?

DavidKiryazi 29-Aug-10 5:41am
my appologies anh chu, I misunderstood the initial problem. I will look and see if there is a method to get at the names of the devices. In the mean time, maybe someone else will reply :)


Actually I solved the problem with try catch statement. So if the software can not try to open 1 port, it will try another port without any problems. However, I would like to know how to use C# to get more information about the USB (COM) port, e.g, VID/PID, Device Name, etc. That's should be very interesting to know.

Thank you for helping me in this,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900