Pyusb: cannot configure

I am trying to make a script (on linux) that can turn the lights on or off in my mouse.

This is the code that I still have:

import usb.core import usb.util import sys interface = 0 dev = usb.core.find(idVendor=0x1532, idProduct=0x0017) def main(): if dev is None: print "device not found" else: print "device found" if dev.is_kernel_driver_active(interface) is True: print "but we need to detach kernel driver" dev.detach_kernel_driver(interface) print "claiming device" usb.util.claim_interface(dev, interface) print "release claimed interface" usb.util.release_interface(dev, interface) print "now attaching the kernel driver again" dev.attach_kernel_driver(interface) print "all done" return 0 if __name__ == '__main__': main() 

This works fine, but if I try to execute: dev.set_configuration ()

after Claim_interface (dev, interface)

script returns error: usb.core.USBError: busy resource

Why is he still busy after I disable his kernel driver?

+6
source share
2 answers

Not sure if this solves, but are udev rules right for your mouse? I had a similar problem with a user device that a friend made for me, and I decided by adding a rule like:

 SUBSYSTEM !="usb_device", ACTION !="add", GOTO="device_rules_end" SYSFS{idVendor} =="1532", SYSFS{idProduct} =="0017", SYMLINK+="mydevice" MODE="0666", OWNER="<your-username-here>", GROUP="root" LABEL="device_rules_end" 

in my /etc/udev/rules.d folder.

NTN!

EDIT: before adding the rule, try running the script with sudo . If it works this way, it is almost certainly a resolution setting that will be set in accordance with the rule above.

+6
source

I also had this problem. Your code works well if you first set_configuration and then request an interface. This is also the order suggested here: http://libusb.sourceforge.net/api-1.0/caveats.html

+4
source

Source: https://habr.com/ru/post/902055/


All Articles