diff --git a/print/barcode_template.txt b/print/barcode_template.txt index 540f7bd..a3ee7d8 100644 --- a/print/barcode_template.txt +++ b/print/barcode_template.txt @@ -1,5 +1,5 @@ -SIZE 76 mm,95 mm -GAP 2 mm,0 +SIZE 76 mm,101 mm +GAP 4 mm,0 DIRECTION 1 DENSITY 8 CLS diff --git a/print/test.txt b/print/test.txt new file mode 100644 index 0000000..1ce9ea9 --- /dev/null +++ b/print/test.txt @@ -0,0 +1,10 @@ +SIZE 76 mm,101 mm +GAP 4 mm,0 +DIRECTION 1 +DENSITY 8 +CLS +QRCODE 10,10,H,4,A,0, "ABCabc123" +QRCODE 160,160,H,4,A,0, "123ABCabc" +QRCODE 310,310,M,4,A,0,M2, "印表機 ABCabc123" +PRINT 1,1 +CUT \ No newline at end of file diff --git a/print/tspl_repl.py b/print/tspl_repl.py new file mode 100644 index 0000000..eeb77bf --- /dev/null +++ b/print/tspl_repl.py @@ -0,0 +1,32 @@ +import win32print + +PRINTER_NAME = "Xprinter XP-350BM" + +def send(tspl_text): + h = win32print.OpenPrinter(PRINTER_NAME) + try: + win32print.StartDocPrinter(h, 1, ("TSPL REPL", None, "RAW")) + win32print.StartPagePrinter(h) + win32print.WritePrinter(h, tspl_text.encode('utf-8')) + win32print.EndPagePrinter(h) + win32print.EndDocPrinter(h) + finally: + win32print.ClosePrinter(h) + +print(f"TSPL REPL — sending to: {PRINTER_NAME}") +print("Type TSPL commands one per line. Type 'PRINT 1,1' to trigger print.") +print("Type 'exit' to quit.\n") + +buffer = [] + +while True: + line = input("tspl> ").strip() + if line.lower() == "exit": + break + buffer.append(line) + # Auto-send whenever a PRINT command is entered + if line.upper().startswith("PRINT"): + full_command = "\n".join(buffer) + "\n" + send(full_command) + print(">> Sent to printer.\n") + buffer = [] \ No newline at end of file