Add skip line and catch printing errors

This commit is contained in:
n07070
2026-06-04 02:32:23 +02:00
parent c57e2f91a2
commit 3a1d9b20fb

View File

@@ -216,6 +216,7 @@ class EscPosPrinter(Printer):
self.printer.textln(clean_msg) self.printer.textln(clean_msg)
if clean_signature: if clean_signature:
self.printer.textln(clean_signature) self.printer.textln(clean_signature)
self.printer.textln()
self.printer.close() self.printer.close()
except Exception as e: except Exception as e:
self.app.logger.error("Unable to print because : " + str(e)) self.app.logger.error("Unable to print because : " + str(e))
@@ -323,24 +324,28 @@ class EscPosPrinter(Printer):
with self._lock: with self._lock:
if self._state: if self._state:
self._state = False self._state = False
match (task_type.value): try:
case "text": match (task_type.value):
self._print_txt(data["txt"], signature=data["sign"]) case "text":
self._state = True self._print_txt(data["txt"], signature=data["sign"])
case "image": self._state = True
self._print_img( case "image":
data["img"], signature=data["sign"], process=data["process"] self._print_img(
) data["img"], signature=data["sign"], process=data["process"]
self._state = True )
case "cut": self._state = True
self._cut() case "cut":
self._state = True self._cut()
case "qr": self._state = True
self._qr(data["txt"]) case "qr":
self._state = True self._qr(data["txt"])
case _: self._state = True
raise RuntimeError("This task type is not supported") case _:
else: raise RuntimeError("This task type is not supported")
except Exception as e:
self._state = True
raise RuntimeError from e
raise RuntimeError("The printer is not ready to print yet !") raise RuntimeError("The printer is not ready to print yet !")