Computer Software Development
  • Reliable Technologies
  • Programming in Ada
  • Real time
  • Embedded and distributed systems
  • Communications


Home    ::    About    ::    Experience    ::     Links    ::     Downloads   ::     Articles   ::     Contact


Download: USB Serial Device Locator (.zip 6.6 KB)


USB Serial Device Locator.

Under MS Windows, USB serial devices are allocated a COM port.
Plugging the device into a different USB port will invariably cause it to be allocated a different port.
The same thing happens if another serial device is plugged into the system whilst the device is disconnected.

Because of this behaviour the serial device cannot be statically configured via an ini file or registry setting.
Locating the device by attempting to converse with it, should also be discouraged because it will often violate protocols of other serial devices.

The ideal solution therefore is for the application that wishes to communicate with the device to be able to determine the COM port to use.

This is what this example program does.
It assumes that the Vendor ID (VID) and Product ID (PID) of the device is known.
These are 16 bit numbers that uniquely identify the device and can be easily determined by using Windows' device manager whilst the device is connected.
(Use the Device Manager, Ports (COM & LPT), Double click on the device, select the Details tab and from the property combobox select Hardware Ids).

The program iterates over every USB device using the Windows system service Setup_Di_Get_Class_Devs
The plug and play device properties are retrieved for each device and compared with the VID and PID being searched for.
For each match the device registry key is extracted and used to obtain the Port name which is added to a list.
This list is then output as the result of the application.



© 2024 White Elephant GmbH   |   Created by Dylan Marriott   |   In association with Polymorphic   |