How can I print images with a thermal printer and python-escpos under Windows 11?

457 Views Asked by At

I can not print images with my thermal printer under Microsoft Windows OS, with python and python-escpos.

  • Python version: 3.11.3
  • Python-escpos version: 3.0a9
  • OS: Windows 11 22H2
  • Thermal printer: OCPP-58E-U

Sample code:

from escpos.printer import Usb

p = Usb(0x0456, 0x0808, in_ep=0x81, out_ep=0x03, profile='POS-5890')
p.charcode(code='AUTO')
p.codepage = 'WPC1250'
p.text('Image printing...')
p.image('test.png')
p.close()

Error message:

Traceback (most recent call last):
  File "F:\Source Code\reward_printer\rewards.py", line 76, in print_something
    p.image('test.png')
  File "C:\Python\Lib\site-packages\escpos\escpos.py", line 210, in image
    self._raw(header + im.to_raster_format())
  File "C:\Python\Lib\site-packages\escpos\printer.py", line 130, in _raw
    self.device.write(self.out_ep, msg, self.timeout)
  File "C:\Python\Lib\site-packages\usb\core.py", line 989, in write
    return fn(
           ^^^
  File "C:\Python\Lib\site-packages\usb\backend\libusb1.py", line 837, in bulk_write
    return self.__write(self.lib.libusb_bulk_transfer,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\usb\backend\libusb1.py", line 938, in __write
    _check(retval)
  File "C:\Python\Lib\site-packages\usb\backend\libusb1.py", line 604, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

Remarks

  • Usb id and vendor are correct. The printer prints the text before the image.
  • The image exists and has no errors. I can open it fine with any image editor.
  • Strangly only a portion of the image prints before the scripts halts with the error message Sample printing
  • [Edit] File formats that I used ( and produce the same error ): PNG, BMP, TIFF, GIF ( static not animated )

Assumption

Is this some kind of usb buffer error?

Question

How can I fix it please?

P.S.

Thank you in advance for your precious time!

0

There are 0 best solutions below