first version of morning edition in python
This commit is contained in:
56
diagnose.py
Normal file
56
diagnose.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Printer diagnostic — runs several test prints to identify character width
|
||||
and font settings on the Epson TM-T88V.
|
||||
"""
|
||||
import subprocess, sys, time
|
||||
|
||||
PRINTER = "receipt"
|
||||
|
||||
ESC = b'\x1b'
|
||||
GS = b'\x1d'
|
||||
|
||||
INIT = ESC + b'\x40' # ESC @ — initialize
|
||||
FONT_A = ESC + b'\x4d\x00' # Font A (12x24 dots) — expected 42 chars
|
||||
FONT_B = ESC + b'\x4d\x01' # Font B ( 9x17 dots) — expected 56 chars
|
||||
SIZE_NORM = GS + b'\x21\x00' # GS ! 0 — force 1x1 character size
|
||||
CUT = GS + b'\x56\x00' # full cut
|
||||
|
||||
RULER_42 = "123456789012345678901234567890123456789012"
|
||||
RULER_56 = "12345678901234567890123456789012345678901234567890123456"
|
||||
|
||||
def send(data: bytes):
|
||||
r = subprocess.run(["lpr", "-P", PRINTER, "-o", "raw"],
|
||||
input=data, capture_output=True)
|
||||
if r.returncode != 0:
|
||||
print("lpr error:", r.stderr.decode(), file=sys.stderr)
|
||||
|
||||
def test(label, extra_init=b"", font=FONT_A, ruler=RULER_42):
|
||||
body = (
|
||||
f"\n--- TEST: {label} ---\n"
|
||||
f"Font: {'A (expect 42)' if font == FONT_A else 'B (expect 56)'}\n"
|
||||
f"{ruler}\n"
|
||||
f"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^\n"
|
||||
f"The quick brown fox jumps over the lazy dog\n"
|
||||
f"\n"
|
||||
).encode("ascii")
|
||||
send(INIT + extra_init + font + body + b"\n\n" + CUT)
|
||||
print(f" Printed: {label}")
|
||||
time.sleep(3)
|
||||
|
||||
print("Running printer diagnostics -- watch the paper!\n")
|
||||
|
||||
print("Test 1: Font A, no GS ! override (baseline -- your current setup)")
|
||||
test("Font A baseline", extra_init=b"", font=FONT_A, ruler=RULER_42)
|
||||
|
||||
print("Test 2: Font A + GS ! 0x00 (force normal 1x1 character size)")
|
||||
test("Font A + GS!00", extra_init=SIZE_NORM, font=FONT_A, ruler=RULER_42)
|
||||
|
||||
print("Test 3: Font B (smaller -- expect 56 chars/line)")
|
||||
test("Font B baseline", extra_init=b"", font=FONT_B, ruler=RULER_56)
|
||||
|
||||
print("Test 4: Font B + GS ! 0x00")
|
||||
test("Font B + GS!00", extra_init=SIZE_NORM, font=FONT_B, ruler=RULER_56)
|
||||
|
||||
print("\nDone. Count where the ruler wraps on each strip.")
|
||||
print("Report which test gave 42+ chars and we'll lock that in.")
|
||||
Reference in New Issue
Block a user