0

I am trying to read data from USB using pyusb in python.I am able to get all the configuration of devices but when i am trying to read data .I am getting the below error:

USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, win error: The requested resource is in use.

PF the code also what i had written :

import usb.core
test = usb.core.find(idVendor=0x0ghe, idProduct=0x0241)
print test

test.set_configuration()

for i in range(0, 20):
    while True:
        try:
            test = test.read(0x81, 8, timeout=50)
            break
        except usb.core.USBError, e:            
            if str(e).find("timeout") >= 0:
                pass
            else:
                raise IOError("USB Error: %s"%str(e))

    print test

Below are my questions:

  1. How to read data from USB in host machine every second whenever we are doing any operation in usb connected device ?
  2. Why this error is coming while reading data from endpoints ?
  3. What's the efficient way to read inputs from USB using pyusb for any button press whatever we are doing in device ?
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Chirag Dhingra
  • 128
  • 2
  • 17
  • Does the behaviour depend on the device? Does any access work using pyusb on your system? – Ulrich Eckhardt Feb 17 '19 at 21:10
  • No it doesn't depend on particular device.Yes it worked for getting the device information having the configuration and interfaces.Only for reading data i am getting problems. – Chirag Dhingra Feb 18 '19 at 07:07

1 Answers1

0

I faced this issue while using pyusb with a custom USB device that I created and with the libusb-win32(v1.2.6.0) driver. I was able to root cause the issue to trying to create multiple references to an already opened device. In my case, I was searching for the device every time I was trying to write to one of the endpoints, but I already had a reference to the device in a previous function call. Maintaining only one reference to the device solved the issue for me.

  • A few lines of code regarding `Maintaining only one reference to the device` showing how to do it and how not to do it might be helpful. – AcK Nov 07 '20 at 17:00