>我需要测试爱普生POS打印机TM-U220PD。我通过并行转换器将其连接到我的笔记本电脑。它已完全安装,但是当我使用 python escpos 测试它时,显示以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/escpos/escpos.py", line 437, in text
self._raw(txt.encode())
File "/usr/local/lib/python2.7/dist-packages/escpos/printer.py", line 85, in _raw
self.device.write(self.out_ep, msg, self.timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 948, in write
self.__get_timeout(timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 824, in bulk_write
timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 920, in __write
_check(retval)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error
这是用于测试的代码:
>>> from escpos.printer import Usb
>>> p = Usb(0x067b, 0x2305)
>>> p.open()
>>> p.text()
这样的USB到并行转换器应该由您的系统安装到文件系统中(我假设您从跟踪来看,您在*nix上)。通常这类似于 /dev/usb/lp0
.
对于第一次调试,您可以尝试只写入此"文件":
echo "Testn" > /dev/usb/lp0
如果这有效,您应该能够成功打印:
from escpos.printer import File
p = File(devfile='/dev/usb/lp0')
p.text("some textn")