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:
h.open(0x0c2e, 0x9a6c) # METROLOGIC VendorID/ProductID
生成错误消息:
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
使用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()
并返回目标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
尝试使用十进制(而不是十六进制)参数打开HID设备:
h.open(3118,39532) # METROLOGIC VendorID/ProductID
也失败了:
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
我们非常感谢任何诊断问题,并且回复将更新到原始帖子。
答案 0 :(得分:1)
我也遇到了同样的问题,但是在谷歌搜索后发现了这个forum。 切换为root用户解决了我的问题。也许您没有足够的权限。
答案 1 :(得分:0)
使用尝试在python2 test5.py之前键入sudo 像那样 : user $ sudo python2 test5.py
答案 2 :(得分:0)
我遇到了同样的问题。
显然你需要添加一个udev规则
在/etc/udev/rules/99-my-device.rules
中:
SUBSYSTEM=="usb", ATTRS{idVendor}=="04d8", MODE="0666", GROUP="plugdev"
注意:您可能需要更新 VID 编号以匹配您的情况。