'How to get the paper status of my Thermal Printer using python-escpos?
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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |