Get COM PORT of USB Serial Device using the VID and PID on Windows

find COM PORT of USB

In my one project, I need to create an application to upgrade the firmware of the device. Here comport is using for the communication. We cannot fix the COM ID of the USB device in the application because the device could be enumerated with different com id on a different machine as per the availability.

So the solution is that displays the list of all known com ports and user select the correct com port. But it is not a good idea to show all com port, I want that application to identify the com id itself.

Every USB device has a unique hardware id (combination of VID and PID), so to accomplish the above task my approach is to find the COM port id on the basis of VID/PID. The registry of the windows kept the information of the device, so simple logic here to open the windows registry and get the com id.

You can See this Article, Read & Write Windows Registry

How to find the VID and PID numbers

To find the vid (Vendor ID) and PID (Product ID) of a serial USB device first you need to attach the device with your PC. Now you need to follow the below steps to get the vid and PID.

1. Go to Control Panel > Device Manager > Ports.

port class

 

2. Select the desire com port and double click on it or right click and select Properties.

port properties

 

3. Go to the Details tab and select Hardware ID to view its PID and VID.

hardware id

 

If you want to learn about windows internal, here 10 Free days windows internal course for you.

C language video course

See the below code to get the COM ID in of a serial USB (Arduino ) in windows machine.

Note: Double click on the code for the better indentation.



Reference: MSDN

Leave a Reply