SetupDiGetDeviceRegistryProperty(..SDRP_ADDRESS...) gets USB hub port?
-
I've spent more than a week on a problem with getting the serial number string descriptor from a USB device that uses USBSER as driver. The USBSER driver doesn't seem to support any kind of functionality for getting the serial number directly and in some cases the device is a composite device which adds to the problem. So I've tried another way... I get the symbolic link for my device either through
WM_DEVICECHANGE
or by enumeration with the Setup API. I enumerate the USB device tree and get hold of the parent hub on which my device is connected and then ask the hub for the string descriptor. So far so good, but... There are two scenarios where I'm afraid this may fail: 1. If a hub with multiple devices attached is inserted, the order of device notifications may not be in "port" order although it seems that way 2. When enumerating devices at application start the enumeration order may not be in "port" order When I iterate through the ports of the parent hub and I find a new device I assume it is the one I got the notification for, but this method fails under the circumstances mentioned above. Mapping the original symbolic link for my device to a specific port number in the parent hub would solve my problem. I think I have found a solution for this, but I cannot find any information that verifies this as a reliable method even though I've google'ed like insane. I useSetupDiGetDeviceRegistryProperty()
and get the "address". The address seems to correspond to the port number of the parent hub. I've tried this on my machine (XP SP3) and it works all right, even if I move things around, add hubs in between and so on. Can anyone verify this as reliable or unreliable, or point me toward some Microsoft-ish information about usingSDRP_ADDRESS
on USB devices? Is it an undocumented feature or pure coincidence? Thanks -- Rog"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
I've spent more than a week on a problem with getting the serial number string descriptor from a USB device that uses USBSER as driver. The USBSER driver doesn't seem to support any kind of functionality for getting the serial number directly and in some cases the device is a composite device which adds to the problem. So I've tried another way... I get the symbolic link for my device either through
WM_DEVICECHANGE
or by enumeration with the Setup API. I enumerate the USB device tree and get hold of the parent hub on which my device is connected and then ask the hub for the string descriptor. So far so good, but... There are two scenarios where I'm afraid this may fail: 1. If a hub with multiple devices attached is inserted, the order of device notifications may not be in "port" order although it seems that way 2. When enumerating devices at application start the enumeration order may not be in "port" order When I iterate through the ports of the parent hub and I find a new device I assume it is the one I got the notification for, but this method fails under the circumstances mentioned above. Mapping the original symbolic link for my device to a specific port number in the parent hub would solve my problem. I think I have found a solution for this, but I cannot find any information that verifies this as a reliable method even though I've google'ed like insane. I useSetupDiGetDeviceRegistryProperty()
and get the "address". The address seems to correspond to the port number of the parent hub. I've tried this on my machine (XP SP3) and it works all right, even if I move things around, add hubs in between and so on. Can anyone verify this as reliable or unreliable, or point me toward some Microsoft-ish information about usingSDRP_ADDRESS
on USB devices? Is it an undocumented feature or pure coincidence? Thanks -- Rog"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
Jan Axelson has written books and articles on this stuff. http://www.lvr.com/[^] Hope the link helps.
Thanks Richard, it's a good link but unfortunately this was the first resource I tried to find information in. Moreover I have in front of me Jan's all editions of "USB Complete" plus the "Serial Port Complete". Her books are very good, as well as her site, but I haven't found anything that clearly states "calling
SetupDiGetDeviceRegistryProperty
withSDRP_ADDRESS
gets the hub port number the device is connected to"... :| I was hoping that someone would have found a similar statement from Microsoft, or someone who has successfully used a similar technique."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown