title: Communication with the USB device in Python
body: <p>I want to communicate with and send data to a USB device. I am able to find the device but while attaching the device with the kernel driver it is giving <code>USB Error: Resource Busy</code>. The following is my code:</p>
  <pre class="lang-py prettyprint-override"><code>import usb
  
  dev = usb.core.find(idVendor=0x0403, idProduct=0x6001)
  dev.set_configuration()
  
  cfg = dev.get_active_configuration()
  
  dev.attach_kernel_driver(interface)
  
  interface_number = cfg[(0, 0)].bInterfaceNumber
  alternate_settting = usb.control.get_interface(interface_number)
  intf = usb.util.find_descriptor(
      cfg, bInterfaceNumber=interface_number,
      bAlternateSetting=alternate_setting)
  
  ep = usb.util.find_descriptor(
      intf, custom_match=lambda e:
      usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
  
  dev.detach_kernel_driver(interface)
  
  ep.write(&quot;\r&quot; + linea1[:19] + &quot;\n\r&quot; + &quot; &quot; * (20 - len(linea2)) + linea2)
  </code></pre>