0

我正在尝试使用 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

我该如何解决这个错误?

4

1 回答 1

0

您必须提供一个后端,即一个libusb实现,可以是 by libusb-0.1、 bylibusb-1.0或 by openusb(如在文件夹中看到的pyusb-<version>\usb\backend)。在您的情况下,libusb-0.1因为您使用libusb-win32了 ,因此 python 脚本必须能够libusb0.dll在库路径中找到。我在这里为这个典型问题提供了一个解决方案:PyUSB ValueError: No backend available

于 2015-02-27T10:09:23.220 回答