from smartx_rfid.devices.printer import SatoWs4Printer, simple_zpl_example
import asyncio
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%H:%M:%S",
)
printer = SatoWs4Printer(ip="192.168.1.102")
print_list = [
simple_zpl_example,
simple_zpl_example.replace("000000000000000000000001", "000000000000000000000002"),
]
def on_event(name: str, event_type: str, event_data=None):
print(f"{name} -> Event: {event_type}, Data: {event_data}")
status, msg = printer.print(simple_zpl_example)
printer.can_print = False
if event_type == "status" and event_data == "ready":
if len(print_list) == 0:
print("No more labels to print.")
exit(0)
status, msg = printer.print(print_list.pop(0))
if not status:
print(f"Print error: {msg}")
if status:
print(f"Print sent, ID: {msg}")
async def main():
printer.on_event = on_event
asyncio.create_task(printer.connect())
while True:
await asyncio.sleep(1)
if __name__ == "__main__":
asyncio.run(main())