2

I need to on/off several usb devices on my python script. Can i bind and unbind usb devices with PyUsb?

I can do it with shell commands:
Power off:
echo "device_nuber" > /sys/bus/usb/drivers/usb/unbind
Power on:
echo "device_nuber" > /sys/bus/usb/drivers/usb/bind

How execute the same in python script?

vakym
  • 61
  • 1
  • 9

1 Answers1

2

You can do this with attach_kernel_driver and detach_kernel_driver.


import usb.core
dev = usb.core.find(idVendor=0x1234,idProduct=0x5678)
# unbind interface 0
dev.detach_kernel_driver(0)
# bind interface 0
dev.attach_kernel_driver(0)

ZhouZhuo
  • 196
  • 2
  • 5