如何使用 python-escpos 获取热敏打印机的纸张状态?

发布于 2025-01-14 11:50:25 字数 519 浏览 0 评论 0原文

目前,我正在开发一个使用热敏打印机的订购系统。

我的代码看起来像这样。

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()

我得到输出

:错误 [Errno 110] 操作超时

我做错了什么?

帮助信息

  • python-escpos==3.0a6
  • 打印机型号 Alpha TP-80H

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一花一树开 2025-01-21 11:50:25

我一开始也使用了python-escpos库来获取论文状态,但是总是报错,当我使用pySerial库来获取论文状态时,我发现它有效!我建议您使用 pySerial 库。
下面是一些简单的例子:

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')

你可以参考这里,我之前写的例子。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文