I am trying to print to a TM-T20II thermal printer so I can print receipts. Here is my code:
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')
I am using a usbdk backend, without it I get a 'NotImplementedError: Operation not supported or unimplemented on this platform.' I'm doing this because for my program to work I need to use the default Epson drivers. When I run this code the error I get is:
<File "C:\Users\maxsl\anaconda3\lib\site-packages\usb\core.py", line 234, in get_interface_and_endpoint return 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 _check raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno None] Other error>
This error only occurs when I add p.text()
in. Finding the printer and everything else is no problem. I also want to say that write()
works in the PyUSB module, but it would be much more convenient for me to not have to translate the outputs in my program to the confusing ESC/P language.
I am using Spyder 4 with anaconda (python 3.7) 64-bit, libusb 1.0.22b9, most recent pyusb on github (PyPi version got unimplemented error), and python-escpos 3.0a8. I believe they are all 64-bit as well. I have the libusb1.dll from 64x folder in my System32 and the 86x one in SysWoW64 as recommended. I also have Usbdk installed. Please let me know if you have any ideas to fix or if you need more details. Been googling this for like a week.