windows 机器上的 libusb、pyusb 和 python-escpos

libusb, pyusb and python-escpos on a windows machine

我正在尝试在 windows 7(64 位)上使用 Epson POS TM-82 打印机。我已经安装了打印机的驱动程序。我安装了 python 2.7.15(64 位)。为了与 python 一起工作,我正在使用这个包,python-escpos

在我安装 python-escpos 后,尝试将 运行 作为 documented,我收到一个错误:

from escpos.printer import Usb
Usb(0x04b8, 0x0e11)

usb.core.NoBackendError: No backend available

  1. 经过更多挖掘,我发现了这个 wiki,根据这个我需要使用最新版本的 Zadig,一个用于 WinUSB 的自动驱动程序安装程序 GUI 应用程序,libusb-win32和 libusbK.

    所以,我下载了 Zadig;从下拉菜单中选择TM-82,选择WinUSB替换驱动,安装成功。

    在那之后我再次 运行 相同的 python-escpos 从上面记录的命令,并得到同样的错误:

    usb.core.NoBackendError: No backend available

  2. 经过更多研究,我在 Whosebug 上找到了 。所以按照答案,我下载了 libusb zip 文件,并将 libusb-1.0.20_2\MS64\dll\libusb-1.0.lib 复制到我的 C:\Windows\System32。最后将 libusb-1.0.20_2\MS64\static\libusb-1.0.lib 复制到 C:\Python27\libs\

    在那之后我再次 运行 相同的 python-escpos 从上面记录的命令,这次我得到了一个不同的错误:

    NotImplementedError: Operation not supported or unimplemented on this platform

我在这里错过了什么?请你帮助我好吗。谢谢。

在这里回答我自己的问题。所以,事实证明,问题出在 python-escpos 库上。我不得不从 printer.py(该库的 python 模块)中删除以下内容:

try:
    check_driver = self.device.is_kernel_driver_active(0)
except NotImplementedError:
    pass
if check_driver is None or check_driver:
    try:
        self.device.detach_kernel_driver(0)
    except usb.core.USBError as e:
        if check_driver is not None:
            print("Could not detatch kernel driver: {0}".format(str(e)))

详情可以在我的博客Medium上找到。