Change the way a Printer is used by the worker

This commit is contained in:
n07070
2026-10-11 21:42:29 +02:00
parent 960b0e2240
commit d4eb0ed3f9
4 changed files with 59 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ the methods expected from printers.
"""
from collections.abc import Set
import time
import usb.core
import usb.util
from printer import Printer, EscPosPrinter, BrotherPrinter
@@ -41,7 +42,17 @@ class Printers:
# Find all connected USB devices
devices = usb.core.find(find_all=True, custom_match=_FindClass(7))
if not devices:
waiting_time_for_printer = 10
while not list(devices):
self.app.logger.warning(str(waiting_time_for_printer) + " Found no printers, waiting for a printer to connect to the system...")
time.sleep(1)
waiting_time_for_printer = waiting_time_for_printer - 1
devices = usb.core.find(find_all=True, custom_match=_FindClass(7))
if waiting_time_for_printer == 0:
break
if not list(devices):
self.app.logger.warning(
"No USB devices of class 7 ( printers ) found or pyusb could not access the bus."
)
@@ -60,6 +71,7 @@ class Printers:
product = usb.util.get_string(dev, dev.iProduct)
except Exception:
product = "Unknown"
self.app.logger.debug(
"Looking at %s %s (%s:%s)",
manufacturer,