0

Currently, I am developing an ordering system that uses a thermal printer.

my code looks like this.

from escpos.printer import Usb
p = Usb(idVendor=0x471, idProduct= 0x55,in_ep=0x82, out_ep=0x02)

try:
    p.text('Hello +\n')
    status = p.paper_status()
    # status = p._read()
    print(status)
    p.cut()

except Exception as e:
    print('error', e)

p.close()

I get the output

: error [Errno 110] Operation timed out

what am I doing wrong?

HELPFULL INFO

  • python-escpos==3.0a6
  • printer model Alpha TP-80H
George Pamfilis
  • 1,397
  • 2
  • 19
  • 37
  • The data may be unidirectional(send only) as a printer specification. If the vendor provides a serial port driver, try changing the printer mode, installing the device driver, and communicating in `Serial` class instead of `USB` class. If not, please try to get the information by `get_port_status` of USBPRINT specification and judge the existence of paper. However, I don't know if I can do that with python-escpos, so I don't have any further information. [USB DevClass for Printing...](https://www.usb.org/sites/default/files/usbprint11a021811.pdf) – kunif Mar 20 '22 at 00:35

1 Answers1

0

I also used the python-escpos library to get the paper status at first, but I always got an error, when I used the pySerial library to get the paper status, I found it works! I recommend you to use the pySerial library.
Here are some simple examples:

import serial

# connect your serial port
serialPort = serial.Serial(
    port="COM2",
    baudrate=115200,
    bytesize=8,
    parity="N", 
    stopbits=1,
    timeout=1.00)

# Write a ESC/POS command to get the paper status
get_paper_roll_sensor_status= serialPort.write(b'\x10\x04\x04')

# Read the returned hexadecimal
paper_status = serialPort.read().hex()

# Print according to the hexadecimal value returned by the printer
if paper_status == "12":
    print('Paper adequate')
elif paper_status == "1e":
    print('Paper near-end is detected by the paper roll near-end sensor')
elif paper_status == "72":
    print('Paper roll end detected by paper roll sensor')
elif paper_status == "7e":
    print('Both sensors detect that the printer is out of paper')
else:
    print('other unset values')

You can refer to here, the example I wrote before.

Daoxue Wu
  • 1
  • 1