CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2013

    Identifying physcal USB slot an USB device is attached to


    I have an applicattion in Windows 7 that uses two USB handsets plugged to specific physical external USB slots in a PC (eg: the left side USB slot and the right-side USB slot in a tablet).

    The application needs to handle differently those handsets, based on the physical external USB slots they are plugged in. So far I have got to discover Location Information via SetupDiGetDeviceRegistryProperty() with parameter SPDRP_LOCATION_INFORMATION.

    That gives me a string like "Port_#0004_Hub_#0006" that i can MANUALLY AND BY INSPECTION associate with external physical USB slots for a given hardware system. But that isn't very reliable and persistent, since it varies with many things like Windows version installed, variability between units of the same model of PC, etc.

    Is there a consistent procedure of identification that is :
    1. stable across restarts of the system
    2. stable across installations of new devices, Windows or drivers updates, or reinstallations of Windows. 3. stable across plugging of additional USB
    4. stable across different units of the same computer model

    I have been warned by some knowledgeable guys that this is unachievable, but i still hope a better luck!

    Many thanks for any help.

  2. #2
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: Identifying physcal USB slot an USB device is attached to

    Part of the whole point of USB is that at the client level you don't know where something is connected.

    The handset could be connected via a daisy-chain in your screen, with the screen connected to an external USB hub and the USB hub connected to a port on the exterior of your PC which is again part of a USB hub on your motherboard.

    Going low level you can obtain the actual connection tree, but... what are you going to do with this ?

    The function you have now will give you a unique ID for each USB device.
    If you somehow want to have a guaranteed "plugged into port 1" and "plugged into port 2" type answer, then... No, sorry, this isn't how USB works. Some PC's may not even have "Port_#0001" physically connected or may have all USB devices on the same internal "Port_#0001".

    Possible solutions are: See if the actual devices have unique ID's of their own that may be of some use.
    Offer a User interface system where users have to manually select the "left" and "right" device. which you identify by port number. So long as they don't physically reconfigure, this should be stable across reboots.

  3. #3
    Join Date
    Feb 2013

    Re: Identifying physcal USB slot an USB device is attached to

    Thank you, OReubens

    The aim of my requirement is to be able to deploy e.g. 200 tablets of the same model, each one with two handsets plugged (one "left" in a pre-conventioned USB physical slot and the other "right" in another pre-conventioned USB physical slot) and donīt have to overburden the technician or the final user with any manual step of setup.

    Your first suggestion, as I understood, could be using USB devices serial number from the USB device descriptor.
    I am considering that approach as a last resort. It would boil down to differentiating visually "left" handset from "right" ones and programming different kinds of serial numbers for the two cases. The software then would identify which is left and which is right based on reading of serial number. Thatīs doable, although a bit awkward in the previous process of marking left and right handsets and programming differently the serial numbers for both types.

    Your second suggestion as requires manual configuration is exactly what i want to avoid.

    My ideal solution would be finding a programatically readable property whose value can be associated in a stable way with the external physical USB ports, for A GIVEN PC MODEL, KNOWING THERE WILL BE NO ADDITION OF EXTERNAL USB HUBS.
    To my dismay some have told me that even systems of the same manufacturer and model can give different readings of devices location (hub, usb) for some physical port.

    It seems you are in agreement with that skeptical opinion, and I am doomed.

    I am wondering if DEVPKEY_Device_PhysicalDeviceLocation (available only in Windows 8) could be a kind of solution to the problem.

    Many Thanks.

  4. #4
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: Identifying physcal USB slot an USB device is attached to

    I'm afraid you are indeed doomed.

    Even within a specific model, there are small variations that happen "over time" as the model undergoes revisions, or as components the assembler uses get revised. The manufacturer will of course have to guarantee the same "minimum" as in the original spec (such as stating a PC has X number of USB ports), but I have had motherboards of several revisions that actually have more/better options than the specs/manual prescribes.

    You can get some guarantees for pc's that all come from the same production batch, but if they're from different revisions, all bets are off. Even if you order them all on the same day, there's no guarantee you'll get all units from the same production batch/revision. If this is a requirement, you'll have to explicitely list it on the ordering form. But then you could be in trouble when you need replacement units or extra units lateron.

    This is an option of course, you can query the pc's revision number and hardcode the USB layout for each model/revision you're supporting. That may work for a closed in-house type problem but would be impossible in something you want to sell off the shelf (or online).

    Even if all of this works for you... Can you really guarantee that someone won't disconnect the handsets, possibly connect them wrong. May need replacement of left or right handsets. etc. etc.

    Some ways around things...
    * Simply assume one is left and the other right, and offer an option in your program to swap left and right.
    * If you don't see the 2 expected device serial numbers on the expected port numbers. Make the program enter configuration mode out of it's own.
    * have the user plug in the left (or right) device first, detect it, then let them plug in the other one.
    * there are USB minihubs (even with just 2 ports). Simply require both devices to be connected through a single hub, with the left (or right) on the lower subport or vice versa.
    * there's other ways you can work your way out of this mess for sure

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)