Add skip line and catch printing errors
This commit is contained in:
@@ -216,6 +216,7 @@ class EscPosPrinter(Printer):
|
||||
self.printer.textln(clean_msg)
|
||||
if clean_signature:
|
||||
self.printer.textln(clean_signature)
|
||||
self.printer.textln()
|
||||
self.printer.close()
|
||||
except Exception as e:
|
||||
self.app.logger.error("Unable to print because : " + str(e))
|
||||
@@ -323,24 +324,28 @@ class EscPosPrinter(Printer):
|
||||
with self._lock:
|
||||
if self._state:
|
||||
self._state = False
|
||||
match (task_type.value):
|
||||
case "text":
|
||||
self._print_txt(data["txt"], signature=data["sign"])
|
||||
self._state = True
|
||||
case "image":
|
||||
self._print_img(
|
||||
data["img"], signature=data["sign"], process=data["process"]
|
||||
)
|
||||
self._state = True
|
||||
case "cut":
|
||||
self._cut()
|
||||
self._state = True
|
||||
case "qr":
|
||||
self._qr(data["txt"])
|
||||
self._state = True
|
||||
case _:
|
||||
raise RuntimeError("This task type is not supported")
|
||||
else:
|
||||
try:
|
||||
match (task_type.value):
|
||||
case "text":
|
||||
self._print_txt(data["txt"], signature=data["sign"])
|
||||
self._state = True
|
||||
case "image":
|
||||
self._print_img(
|
||||
data["img"], signature=data["sign"], process=data["process"]
|
||||
)
|
||||
self._state = True
|
||||
case "cut":
|
||||
self._cut()
|
||||
self._state = True
|
||||
case "qr":
|
||||
self._qr(data["txt"])
|
||||
self._state = True
|
||||
case _:
|
||||
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 !")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user