I am looking for example code in ansi c/c++ that will find usb devices by their pid/vid/sn# and then find the associated comport number. I have multiple FTDI usb serial ports connected to a pc and need to identify each port by the known SN#. This code I found will display the HWID info but how do I use it to get the comport number? Here is a response to the below code for one of the devices: USB\VID_0403&PID_6001\FTAME7HK Are there an online tutorial that runs through examples for this type of code?
#include <windows.h>
#include <ansi_c.h>
#include <Setupapi.h>
#include <devguid.h>
#include <Setupapi.h>
HDEVINFO deviceInfoSet;
GUID *guidDev = (GUID*) &GUID_DEVCLASS_USB;
TCHAR buffer [4000];
DWORD buffersize =4000;
int memberIndex = 0;
main()
{
deviceInfoSet = SetupDiGetClassDevs(guidDev, NULL, NULL, DIGCF_PRESENT | DIGCF_PROFILE);
while (TRUE) {
SP_DEVINFO_DATA deviceInfoData;
ZeroMemory(&deviceInfoData, sizeof(SP_DEVINFO_DATA));
deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
if (SetupDiEnumDeviceInfo(deviceInfoSet, memberIndex, &deviceInfoData) == FALSE) {
if (GetLastError() == ERROR_NO_MORE_ITEMS)
{
break;
}
}
DWORD nSize=0 ;
SetupDiGetDeviceInstanceId (deviceInfoSet, &deviceInfoData, buffer, sizeof(buffer), &nSize);
buffer [nSize] ='\0';
printf ("%s\n", buffer);
memberIndex++;
}
if (deviceInfoSet) {
SetupDiDestroyDeviceInfoList(deviceInfoSet);
}
getchar();
return 0;
}