admin管理员组文章数量:1384158
I never used Python ESC/POS before and I started doing a restaurant app that has print-order function running on my VPS as a docker container.
My printing is working fine, currently I'm trying to avoid port forwarding to print orders, but I think that cannot be done using Network Printer.
from escpos.printer import Network
...
@app.route("/print-order", methods=["POST"])
def print_order():
order_id = request.form.get('order-id')
# I used Network with port forwarding
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
PRINTER_IP = config['user_ip']
PRINTER_PORT = 9100
printer = Network(PRINTER_IP, PRINTER_PORT)
try:
conn = get_db_connection()
cur = conn.cursor()
cur.execute("SELECT id, phone, date, total, items FROM orders WHERE id = ?", (order_id,))
order = cur.fetchone()
conn.close()
printer.set(align="center", font=1, bold=True, custom_size=True, width=2, height=2, smooth=True)
printer.text(f"Example Restaurant")
...
printer.cut()
except requests.exceptions.RequestException as e:
logger.debug(f"Failed to print order: {e}")
printer.close()
return redirect('/orders')
print("Print successful!")
printer.close()
return redirect('/ordering')
Do you have an idea that how can I make my app automatically detect like an Usb Printer when its connected to the user's device? Or do I have any other options for Network printing?
The goal would be to make the app more user friendly, so people don't need to setup either Port Forwarding (for Networking) or VID/PID (for Usb).
本文标签: flaskRecognize thermal printer using pythonescposStack Overflow
版权声明:本文标题:flask - Recognize thermal printer using python-escpos - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744441627a2606463.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论