diff --git a/mac/daemon.py b/mac/daemon.py index f1ddf6c..91f2084 100644 --- a/mac/daemon.py +++ b/mac/daemon.py @@ -67,20 +67,17 @@ def do_print(body, encode): return {'ok': False, 'error': str(e)} with LOCK, Urovo() as p: - # 1) direct thermal. Wait out transient busy states before feeding to clear, - # so we don't waste a label on a momentary post-print code. - p.ribbon_off() - time.sleep(0.4) - if p.wait_ready(3.0) != 0x00: - st = p.recover() - if st != 0x00: - return {'ok': False, 'error': 'printer not ready', - 'status': st, 'statusText': status_text(st)} - - # 2) geometry, then the artwork - geometry(p, prof) - p.cls() - + # ENCODE BEFORE GEOMETRY. Order matters on this firmware, and it cost most of a day: + # the SIZE/GAP/TEAR/DIRECTION/CLS burst that sets up a print silences the UHF module + # -- every UHF READ/QUERY afterwards returns no bytes at all until a power-cycle -- + # so an encode placed after it always failed its own read-back with "before: null", + # which looks exactly like a chip that never reached the antenna. It had. The module + # was fine right up until the geometry went out (a standalone /read-tag a second + # earlier read the chip every time; SET RIBBON OFF + FORMFEED provably do not kill + # it). UHF WRITE commits immediately and needs no geometry, and printing works fine + # AFTER geometry, so: read, write, verify on the untouched module first; only then + # set up the print. Nothing feeds in between, so the label at the antenna is the one + # that prints. before = verified = None if encode: # Deliberately NO `SET RFID` here. It was tried as an "arm the radio first" step and @@ -100,6 +97,18 @@ def do_print(body, encode): return {'ok': False, 'error': 'RFID encode failed verification', 'epc': epc, 'epcBefore': before, 'readBack': p.read_uhf(), 'note': 'nothing printed -- no label wasted'} + # 1) direct thermal. Wait out transient busy states before feeding to clear, + # so we don't waste a label on a momentary post-print code. + p.ribbon_off() + time.sleep(0.4) + if p.wait_ready(3.0) != 0x00: + st = p.recover() + if st != 0x00: + return {'ok': False, 'error': 'printer not ready', + 'status': st, 'statusText': status_text(st)} + # 2) geometry, then the artwork -- AFTER the encode, see above + geometry(p, prof) + p.cls() p.write(label.to_tspl(label.render(body, prof))) # 4) re-assert ribbon-off immediately before firing