2

Description: Trying to read mouse data with below code but getting error as given below. please help if anyone has gone through same issue.purpose of doing this is i have read data from the device which is connected as HID device so by the time trying with mouse.

CODE:

import usb.core
import usb.util
import sys
import usb.backend.libusb1

Vendor_ID = 0x0461
Product_ID =0x4E22

dev=usb.core.find(idVendor=Vendor_ID,idProduct=Product_ID)

if dev is None:
    raise ValueError('device not found')
    sys.exit(1)
else:
    print("Device Found")
    usb.util.claim_interface(dev,0)
    dev=usb.core.find(idVendor=Vendor_ID,idProduct=Product_ID)

try:
   dev.set_configuration()
   print ("Configuration set")

except:
  print("configuration not set")

data =dev.read(0x81,4)
print(data)

usb.util.release_interface(dev, 0)

OUTPUT:

    Device Found
    Configuration set
    Traceback (most recent call last):
    File "USB_Read.py", line 27, in <module>
    data =dev.read(0x81,4)
    File "C:\Python\lib\site-packages\usb\core.py", line 983, in read
    ret = fn(
    File "C:\Python\lib\site-packages\usb\backend\libusb1.py", line 846, in intr_read
    return self.__read(self.lib.libusb_interrupt_transfer,
    File "C:\Python\lib\site-packages\usb\backend\libusb1.py", line 936, in __read
    _check(retval)
    File "C:\Python\lib\site-packages\usb\backend\libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
    usb.core.USBError: [Errno 5] Input/Output Error
Rahul Gharole
  • 21
  • 1
  • 2
  • If the mouse is under control of a driver you will not be able to access it directly. – Klaus D. Aug 11 '20 at 06:06
  • I'm having the same issue for a lab power supply. Did you find a solution? I checked with `dev.is_kernel_driver_active(0)`, which is false in my case. So @KlausD., this does not seem to be the problem. – pixelpress Aug 17 '20 at 07:48

1 Answers1

1

Setting LIBUSB_DEBUG like this:

sudo env LIBUSB_DEBUG=1  python USB_Read.py

you get more information that may help solving the problem.

Well I fixed

usb.core.USBError: [Errno 5] Input/Output Error

like this. Go to /etc/udev/rules.d/ and create a file Primax.rules with the following content:

SUBSYSTEM=="usb",        ATTRS{idVendor}=="0461", MODE="0666"
SUBSYSTEM=="usb_device", ATTRS{idVendor}=="0461", MODE="0666"

Note you need to change that 0461 (what is the vendorID of Primax) to the one of you're device. (...or just entirely kick out that ATTRS..., part)

so before it looked like this: (Note i was targeting Bus 003 Device 022)

cd /dev/bus/usb/003
ls -l

crw-rw-r-- 1 root root 189, 256 18. Mär 15:38 001
c--------- 1 root root 189, 276 18. Mär 15:25 022

after the change with the rules file and (re-Plug Device):

crw-rw-r-- 1 root root 189, 256 18. Mär 15:38 001
crw-rw-rw- 1 root root 189, 278 18. Mär 15:56 022
Nadu
  • 2,401
  • 1
  • 25
  • 30