I want to determine if a specific device is connected to a COM port. I currently have the following code, which uses QueryDosDevice to determine MS-DOS device names
TCHAR lpTargetPath[5000];
for (int i = 0; i < 255; i++) // checking ports from COM0 to COM255
{
std::string str = "COM" + std::to_string(i);
DWORD test = QueryDosDevice(str.c_str(), lpTargetPath, 5000);
// Test the return value and error if any
// If successful, test = # of characters stored in lpTargetPath
// If not
if (test != 0) //QueryDosDevice returns zero if it didn't find an object
{
std::cout << str << ": " << lpTargetPath << std::endl;
}
if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
cout << "buffer error" << endl;
}
}
However, this just returns general device names as follows:
COM3: \Device\Serial0
COM6: \Device\USBSER000
Is there some other method to determine more specific information about the device so I can verify if a particular device is connected? Would the best way just be to poll the COM ports in use for some sort of signature input that would identify the device, or can I actually access serial numbers or some unique identifier (note the display name is just "USB Serial Device(COM6)" so not much help there)