Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming your using Linux and <code>libusb-1.0</code> as a <code>PyUSB</code>'s backend library. </p> <p>According to the <a href="http://libusb.sourceforge.net/api-1.0/group__dev.html" rel="noreferrer">libusb documentation</a>:</p> <pre><code>// Detach a kernel driver from an interface. // If successful, you will then be able to claim the interface and perform I/O. int libusb_detach_kernel_driver (libusb_device_handle *dev, int interface_number) // Re-attach an interface's kernel driver, which was previously // detached using libusb_detach_kernel_driver(). int libusb_attach_kernel_driver(libusb_device_handle *dev, int interface_number) </code></pre> <p>So basically, you need to call <code>detach_kernel_driver</code> <strong>first</strong> to detach already attached kernel driver (if any) from the device's interface, so you can communicate with it in your code (it's either your code or some kernel driver talking to the device's interface). When you're done, you may want to call <code>attach_kernel_driver</code> to re-attach the kernel driver again.</p> <p>I believe there's no need to call any of those C functions/Python methods if you can ensure that no kernel driver is loaded for a given device (or manually unload it before running your code). </p> <p><strong>Edit:</strong> </p> <p>I just got this piece of code (based on your sample) working. Note: for simplicity I've hardcoded 0 as interface number for <code>detach_kernel_driver</code> and <code>attach_kernel_driver</code> - you should make it smarter, I suppose.</p> <pre><code>import usb dev = usb.core.find(idVendor=0x0403, idProduct=0x6001) reattach = False if dev.is_kernel_driver_active(0): reattach = True dev.detach_kernel_driver(0) dev.set_configuration() cfg = dev.get_active_configuration() interface_number = cfg[(0,0)].bInterfaceNumber alternate_settting = usb.control.get_interface(dev, interface_number) intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number, bAlternateSetting = alternate_settting) ep = usb.util.find_descriptor(intf,custom_match = \ lambda e: \ usb.util.endpoint_direction(e.bEndpointAddress) == \ usb.util.ENDPOINT_OUT) ep.write("test\n\r") # This is needed to release interface, otherwise attach_kernel_driver fails # due to "Resource busy" usb.util.dispose_resources(dev) # It may raise USBError if there's e.g. no kernel driver loaded at all if reattach: dev.attach_kernel_driver(0) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload