none
Enumerate USB devices RRS feed

  • Question

  • Hi,

    I am considering to develop a C# Application witch is going to handle the information read from 6 USB scanners that would be connected to the same computer.

    My question is:
    Is it possible to enumerate the devices, so that, each of them would have a unique ID?

    If I plug or unplug one of those USB scanners, Is it possible to identify which one was plugged or unplugged? (to get back the same ID if plugged again)

    Thanks,
    kikeman,
    Tuesday, July 21, 2009 10:53 PM

Answers

  • The SetupDI api allows you to enumerate hardware (its the api used in the device manager) you can find documentation on it here , its one of the less friendly api's to work with even in C/C++ so be prepared to pull out some hairs in utter frustration before you venture this way. If you fetch the device isntance id (unique id for all hardware inside your pc) you should be able to determine which device got unplugged/plugged in,
    • Marked as answer by Kikeman Wednesday, July 22, 2009 6:53 PM
    Wednesday, July 22, 2009 1:17 AM
  • You might also want to checkout Pos .Net (http://msdn.microsoft.com/en-us/library/ms828083(WinEmbedded.10).aspx) which supports USB devices, specifically barcode scanners, and if you have the correct service objects or you setup an xml file will support plug and play. This defintely allows you to enumerate the devices as well.

    If you went with this option you could either use a logical name (if you can configure on and still have the plug and play work, depends on the service object it seems) or you could try the hardware path property of the device, but I'm not sure if that would change sometimes.
    • Marked as answer by Kikeman Wednesday, July 22, 2009 6:54 PM
    Wednesday, July 22, 2009 2:29 AM
  • Technically it is possible.  The USB_DEVICE_DESCRIPTOR has an iSerialNumber field that the manufacturer may use to specify a unit specific serial number.  Whether the manufacturer of your scanner actually used this is an open question.  One hint should be in the manual, it would have to be a programmable feature that can be setup independent for each device.  There is otherwise nothing available from the USB bus interface that would allow you to identify the device unit or the port it got plugged into.

    Hans Passant.
    • Marked as answer by Kikeman Wednesday, July 22, 2009 6:54 PM
    Wednesday, July 22, 2009 2:29 AM
    Moderator

All replies

  • The SetupDI api allows you to enumerate hardware (its the api used in the device manager) you can find documentation on it here , its one of the less friendly api's to work with even in C/C++ so be prepared to pull out some hairs in utter frustration before you venture this way. If you fetch the device isntance id (unique id for all hardware inside your pc) you should be able to determine which device got unplugged/plugged in,
    • Marked as answer by Kikeman Wednesday, July 22, 2009 6:53 PM
    Wednesday, July 22, 2009 1:17 AM
  • You might also want to checkout Pos .Net (http://msdn.microsoft.com/en-us/library/ms828083(WinEmbedded.10).aspx) which supports USB devices, specifically barcode scanners, and if you have the correct service objects or you setup an xml file will support plug and play. This defintely allows you to enumerate the devices as well.

    If you went with this option you could either use a logical name (if you can configure on and still have the plug and play work, depends on the service object it seems) or you could try the hardware path property of the device, but I'm not sure if that would change sometimes.
    • Marked as answer by Kikeman Wednesday, July 22, 2009 6:54 PM
    Wednesday, July 22, 2009 2:29 AM
  • Technically it is possible.  The USB_DEVICE_DESCRIPTOR has an iSerialNumber field that the manufacturer may use to specify a unit specific serial number.  Whether the manufacturer of your scanner actually used this is an open question.  One hint should be in the manual, it would have to be a programmable feature that can be setup independent for each device.  There is otherwise nothing available from the USB bus interface that would allow you to identify the device unit or the port it got plugged into.

    Hans Passant.
    • Marked as answer by Kikeman Wednesday, July 22, 2009 6:54 PM
    Wednesday, July 22, 2009 2:29 AM
    Moderator
  • When an USB device doesn't support a serial number (or if its disabled though a registry setting) the OS uses the port and bus in the device instance path to create a unique identifier.
    Wednesday, July 22, 2009 3:34 AM