我试图用pyusb和pyusb-keyboard-a-like接管条形码扫描仪。
我有一个运行win7的系统。我安装了带有libusb-win32
过滤器和inf-wizard的usb驱动程序。
我的代码看起来像这样:
from keyboard_alike import reader
class BarCodeReader(reader.Reader):
pass
if __name__ == "__main__":
reader = BarCodeReader(0x0c2e, 0x0b41, 84, 6, should_reset=False)
reader.initialize()
print(reader.read().strip())
reader.disconnect()
并给我以下错误:
Traceback (most recent call last):
File "C:\Users\Alexander\Downloads\pyusb-keyboard-alike-master\pyusb-keyboard-alike-master\lindy_bar_code_scanner.py", line 14, in <module>
reader.initialize()
File "C:\Users\Alexander\Downloads\pyusb-keyboard-alike-master\pyusb-keyboard-alike-master\keyboard_alike\reader.py", line 37, in initialize
self._device = usb.core.find(idVendor=self.vendor_id, idProduct=self.product_id)
File "C:\Python27\lib\site-packages\usb\core.py", line 846, in find
raise ValueError('No backend available')
ValueError: No backend available
我该如何解决此错误?
答案 0 :(得分:0)
您必须通过libusb
,libusb-0.1
或libusb-1.0
提供后端,即openusb
实施(如pyusb-<version>\usb\backend
文件夹中所示})。在您的情况下,由于您使用了libusb-0.1
,因此它是libusb-win32
,因此python脚本必须能够在库路径中找到libusb0.dll
。我在这里为这个典型问题提供了一个解决方案:PyUSB ValueError: No backend available。