简体   繁体   English

Python HIDAPI 故障排除:open() 失败

[英]Python HIDAPI troubleshooting: open() failures

OS X \\ Python 2.7.15 is outfitted with a USB scanner: OS X \\ Python 2.7.15 配备了 USB 扫描仪:

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

The python statement that attempts to open the HID device: 试图打开 HID 设备的 python 语句:

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 :使用Python HIDAPI枚举 HID 设备:

### 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:并返回目标 HID 设备信息:

                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:尝试使用十进制(而不是十六进制)参数打开 HID 设备:

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? h.open() 参数不正确吗?
  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.感谢任何诊断问题,并将回复更新到原始帖子。

I also got same problem, but after googling, found this forum .我也遇到了同样的问题,但在谷歌搜索后,找到了这个论坛 Switching to root user solved my problem.切换到 root 用户解决了我的问题。 Maybe you did not have enough permission.也许你没有足够的权限。

使用尝试像这样输入 sudo defore python2 test5.py : user$sudo python2 test5.py

当我不在sudo下运行时,我遇到了同样的问题,问题是必须设置或配置什么以便不必在sudo下运行?

I encountered the same issue.我遇到了同样的问题。

Apparently you need to add a udev rule显然你需要添加一个 udev 规则

In /etc/udev/rules/99-my-device.rules :/etc/udev/rules/99-my-device.rules

SUBSYSTEM=="usb", ATTRS{idVendor}=="04d8", MODE="0666", GROUP="plugdev"

Note: you may want to update the VID number to match your case.注意:您可能需要更新 VID 编号以匹配您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM