gpt4 book ai didi

python - 将 text() 与 python-escpos 一起使用时,我得到 [Errno None] 和 key error = 1 (windows 10)

转载 作者:行者123 更新时间:2023-12-04 09:30:52 27 4
gpt4 key购买 nike

我正在尝试使用 TM-T20II 热敏打印机打印收据。这是我的代码:

from escpos import printer
from escpos import *
import escpos
from escpos import config
import usb.core
import usb.util
import usb.backend.libusb1
from ctypes import c_void_p, c_int

backend = usb.backend.libusb1.get_backend(find_library=lambda x: "libusb-1.0.dll")
backend.lib.libusb_set_option.argtypes = [c_void_p, c_int]
backend.lib.libusb_set_option(backend.ctx, 1)
p = printer.Usb(0x04b8,0x0e15,0,0x82,0x01, backend=backend)

p.text('test')
我正在使用 usbdk 后端,如果没有它,我会收到“NotImplementedError: Operation not supported or unimplemented on this platform”。我这样做是因为为了让我的程序正常工作,我需要使用默认的 Epson 驱动程序。当我运行此代码时,我得到的错误是:

<File "C:\Users\maxsl\anaconda3\lib\site-packages\usb\core.py", line234, in get_interface_and_endpointreturn self._ep_info[endpoint_address]

KeyError: 1

During handling of the above exception, another exception occurred:

File"C:\Users\maxsl\anaconda3\lib\site-packages\usb\backend\libusb1.py",line 604, in _checkraise USBError(_strerror(ret), ret, _libusb_errno[ret])

USBError: [Errno None] Other error>


仅当我添加 p.text() 时才会出现此错误在。找到打印机和其他一切都没有问题。我也想说 write()在 PyUSB 模块中工作,但对我来说不必将程序中的输出翻译成令人困惑的 ESC/P 语言会更方便。
我正在使用 Spyder 4 和 anaconda (python 3.7) 64 位、libusb 1.0.22b9、github 上的最新 pyusb(PyPi 版本出现未实现的错误)和 python-escpos 3.0a8。我相信它们也是 64 位的。我在 System32 中有来自 64x 文件夹的 libusb1.dll,在 SysWoW64 中有 86x 文件夹。我也安装了 Usbdk。如果您有任何要解决的想法或需要更多详细信息,请告诉我。已经在谷歌上搜索了一个星期。

最佳答案

是不是打印机的USB模式设置有问题?
TM-T20II打印机有USB厂商定义类(COM Port)和USB打印机类两种模式。
VID/PID 分别为 USB 供应商定义的 class=0x04b8:0x0202 和 USB 打印机 class=0x04b8:0x0e15。
TM-T20II Technical Reference Guide第 89 页
您应该可以使用打印机的设置实用程序对其进行更改。
或者,尝试将 PID 指定按原样更改为 0x0202,或尝试作为 COM 端口而不是原始 USB 设备进行通信。

或者,高级打印机驱动程序或 Windows 打印后台处理程序可能已在使用该设备,而其他程序无法使用。
如果已安装设备驱动程序,请尝试将其卸载。

关于python - 将 text() 与 python-escpos 一起使用时,我得到 [Errno None] 和 key error = 1 (windows 10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62852884/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com