Search code examples
pythonlinuxusbsysfs

How to determine sysfs devpath from USB device VID and PID in Python?


I need to locate a USB device in sysfs tree from its VID and PID in Python. What would be the most sensible approach here? Recursively scanning the directory tree is the only idea that comes to my mind. Are there any better approaches? I can't use libusb bindings, by the way.


Solution

  • You might try using the sysfs path for usb devices, /sys/bus/usb/devices/, and globbing for the idProduct and idVendor files

    /sys/bus/usb/devices/*/idProduct
    /sys/bus/usb/devices/*/idVendor