Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python HIDAPI troubleshooting: open() failures

OS X \ Python 2.7.15 is outfitted with a USB scanner:

user$ lsusb | grep Metrologic
Bus 250 Device 005: ID 0c2e:9a6c 0c2e Metrologic Scanner 

The python statement that attempts to open the HID device:

h.open(0x0c2e, 0x9a6c)  # METROLOGIC VendorID/ProductID

produces an error message:

user$ python2 test5.py
Traceback (most recent call last):
  File "test5.py", line 46, in <module>
    h.open(0x0c2e, 0x9a6c)  # METROLOGIC VendorID/ProductID
  File "hid.pyx", line 66, in hid.device.open
IOError: open failed

HID devices are enumerated with the Python HIDAPI:

### enumerate USB devices
for d in hid.enumerate():
    keys = list(d.keys())
    keys.sort()
    for key in keys:
        print("%s : %s" % (key, d[key]))
    print()

and returns the target HID device info:

                interface_number : -1
                manufacturer_string : Metrologic
                path : IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC2@1A,7/EHC2@fa000000/PRT1@fa100000/IOUSBHostDevice@fa100000/AppleUSB20InternalHub@fa100000/PRT3@fa130000/Metrologic Scanner@fa130000/IOUSBHostInterface@0/IOUSBHostHIDDevice@fa130000,0
                vendor_id : 3118     
                product_id : 39532
                product_string : Metrologic Scanner
                release_number : 21574
                serial_number : 
                usage : 6
                usage_page : 1

Attempts to open the HID device with decimal (instead of hexadecimal) arguments:

h.open(3118,39532)      # METROLOGIC VendorID/ProductID

also fail:

user$ python2 test5.py
Traceback (most recent call last):
  File "test5.py", line 47, in <module>
    h.open(3118,39532)      # METROLOGIC VendorID/ProductID
  File "hid.pyx", line 66, in hid.device.open
IOError: open failed

QUESTIONS

  1. Is there enough information here to diagnose or is there another test to be performed to diagnose the failure?
  2. Are the h.open() arguments incorrect?
  3. What are the next steps / strategy to diagnose & correct?

Any diagnostic questions are appreciated and will responses will be update to the original posting.

like image 873
gatorback Avatar asked Jan 28 '26 09:01

gatorback


1 Answers

I also got same problem, but after googling, found this forum. Switching to root user solved my problem. Maybe you did not have enough permission.

like image 134
Shao Chi Avatar answered Jan 31 '26 02:01

Shao Chi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!