I have a wide variety of VCOM devices (FTDI, CP210x, etc) that my program interfaces with, but I need to confirm they are in fact those devices before I begin talking to them. FTDI's D2XX library allows me to pair up the Product/Serial strings with COM number, but I really need a generic solution.
To be clear, I need the USB string descriptors for Product, Serial, and ideally Manufacturer as well. Note these are not the same as the VID/PID numbers, but actual strings. It is okay if I have to get the strings first, and then figure out the COM number for it later.
I am working with good old C cross-compiled using MingW, but really I'm at such a loss for how to do this that a solution in any language would be a step forward.
You should take a look at the Windows Driver Kit samples, or look in to the SetupDi functions (these allow you to enumerate types of devices and query for information). Those functions are documented here: http://msdn.microsoft.com/en-us/library/windows/hardware/ff553567(v=vs.85).aspx#ddk_setupdi_device_interface_functions_dg
I've also posted this a few times, but it is good sample code:
Look at the USBView sample in the WDK. If you are unfamiliar with this, simply run it - this tool walks the entire USB tree on the system and prints out information and descriptor listings for each device.
In your case, I'd start at the RefreshTree() function in this sample, you can then follow the code to see how it enumerates the devices. For each device that you find you can look at the string descriptors.
The easiest way to get the source to this sample is to install the 7.1.0 WDK which is currently available here: http://www.microsoft.com/en-us/download/details.aspx?id=11800
Once you have the VID/PID/Serial Number you should be able to look up the port number in the registry. For example, the CP210x port number will be located at
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_10C4&PID_EA60\0001\Device Parameters\Port Name
in the form of "COMxx" (where VID=10C4, PID=EA60, serial=0001). If you know what the VID/PID is for your device you could skip the USB search and simply parse through the registry to get all devices of that type to discover their COM port numbers.You can also get a list of all COM ports on the system here:
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
. Values will be listed according to their type, so a real serial port will show up with a name\Device\Serialn
and dataCOMxx
, a CP210x will show up with a name\Device\Silabsern
and dataCOMyy
, etc. You can use the name to filter which type of device a COM port belongs to.