#!/usr/bin/env python3 """ TM-T88V paper width NV fix — attempt 2. Tries multiple memory switch group/value combinations. Writes directly to /dev/usb/lp0. """ import sys, time ESC = b'\x1b' GS = b'\x1d' INIT = ESC + b'\x40' FONT_A = ESC + b'\x4d\x00' CUT = GS + b'\x56\x00' DEV = "/dev/usb/lp0" RULER = "123456789|123456789|123456789|123456789|12" def write_dev(data: bytes): with open(DEV, "wb") as f: f.write(data) def gs_e(fn: int, data: bytes) -> bytes: """Build GS ( E pL pH fn [data]""" payload = bytes([fn]) + data pL = len(payload) & 0xFF pH = (len(payload) >> 8) & 0xFF return GS + b'\x28\x45' + bytes([pL, pH]) + payload def strip(label: str, nv_cmd: bytes): body = ( f"\n[{label}]\n" f"{RULER}\n" ).encode("ascii") write_dev(INIT + nv_cmd + INIT + FONT_A + body + b"\n\n" + CUT) time.sleep(4) # ── Memory switch (fn=3): GS ( E 03 00 03 ────────────────── # group 1-8 control different settings; one of them holds paper width. # Trying both 0x00 (all bits clear = 80mm) and 0x80 (bit7 = 80mm candidate). MSW_TESTS = [ # (label, group, value) ("fn3 grp1 val=0x00", 3, 1, 0x00), ("fn3 grp2 val=0x00", 3, 2, 0x00), ("fn3 grp3 val=0x00", 3, 3, 0x00), ("fn3 grp4 val=0x00", 3, 4, 0x00), ("fn3 grp5 val=0x00", 3, 5, 0x00), ("fn3 grp6 val=0x00", 3, 6, 0x00), ("fn3 grp7 val=0x00", 3, 7, 0x00), ("fn3 grp8 val=0x00", 3, 8, 0x00), # Same groups, value=0x80 in case the width bit is bit 7 ("fn3 grp6 val=0x80", 3, 6, 0x80), ("fn3 grp7 val=0x80", 3, 7, 0x80), # Customized values (fn=5): GS ( E 03 00 05 ("fn5 id=0x01 val=0", 5, 0x01, 0x00), ("fn5 id=0x02 val=0", 5, 0x02, 0x00), ("fn5 id=0x03 val=0", 5, 0x03, 0x00), ("fn5 id=0x04 val=0", 5, 0x04, 0x00), ] if __name__ == "__main__": print("Sending NV test strips. Watch for the first one that prints 42 chars wide.") print("Each strip has its label printed on it. Power-cycle after the winning one.\n") for entry in MSW_TESTS: label, fn, param, val = entry nv = gs_e(fn, bytes([param, val])) print(f" Trying: {label}") strip(label, nv) print("\nDone. Tell me which label was the first to print 42 chars wide.") print("If none worked, all strips will be 30 chars and we need a different approach.")