[python-win32] USB device tree physical topology

David Goodger goodger at python.org
Sat Mar 23 18:07:10 CET 2013


Hi all,

I'm working on a project where my Win32 (Win XP and above) will
communicate with a custom hardware device. The device is equivalent to
a USB hub with an SD card reader and a serial-to-USB adapter attached.
My app will communicate with the device via serial-over-USB and
interact with the SD card.

My problem is in figuring out which SD card goes with which serial
adaptor. There could be multiple devices attached, or other serial
adapters or SD card readers attached to the same PC, and I cannot
assume that any SD card is the one that goes with the device.

How can I determine the physical layout of the USB device tree from
Python? Put another way, how can I get a list of devices physically
attached to a specific USB hub?

When I look at my device using the Windows Device Manager
(C:\WINDOWS\System32\devmgmt.msc), I see the physical layout (View ->
Devices by connection). If I right-click on the USB hub at the root of
my device, choose Properties, Details tab, Bus Relations from the
list, I see the sub-devices attached to the USB hub. So the info
exists withing Windows. How can I access this from Python?

Any tips would be welcome, and especially example code (no matter how
simple). I have tried a bunch of things, but I probably missed the
obvious-in-hindsight. Please provide me that hindsight!

-- 
David Goodger <http://python.net/~goodger>


More information about the python-win32 mailing list