Suppose you are using Linux and libusb-1.0 in quality .
According to the libusb documentation :
Basically, you need to call detach_kernel_driver first to disconnect the already connected kernel driver (if any) from the device interface so that you can communicate with it in your code (this is either your code or some kernel driver talking to the device interface). When you're done, you can call attach_kernel_driver to reconnect the kernel driver.
I believe that there is no need to call any of these Python C functions / methods if you can make sure that the kernel driver is not loaded for this device (or manually unload it before running your code).
Edit:
I just got this piece of code (based on your sample). Note: for simplicity, I hardcoded 0 as the interface number for detach_kernel_driver and attach_kernel_driver - you should do it smarter, I suppose.
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")
source share