From 028fdeed6a0457c07294b35b064f3af74a9b4500 Mon Sep 17 00:00:00 2001 From: Mathieu Poussin Date: Tue, 5 Jul 2022 20:29:05 +0200 Subject: [PATCH] Add support for slip/cheque dot matrix printers --- AUTHORS | 4 ++++ src/escpos/constants.py | 6 ++++++ src/escpos/escpos.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/AUTHORS b/AUTHORS index 07c6bce..4ce84bf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,9 +1,11 @@ Ahmed Tahri akeonly +Alejandro Hernández Alexander Bougakov Alex Debiasio Asuki Kono belono +B. Howell Brian Christoph Heuel Cody (Quantified Code Bot) @@ -11,6 +13,7 @@ csoft2k Curtis // mashedkeyboard Davis Goglin Dean Rispin +dependabot[bot] Dmytro Katyukha Gerard Marull-Paretas Hark @@ -21,6 +24,7 @@ Kristi ldos Lucy Linder Manuel F Martinez +Mathieu Poussin Maximilian Wagenbach Michael Billington Michael Elsdörfer diff --git a/src/escpos/constants.py b/src/escpos/constants.py index 80c921c..83edd6a 100644 --- a/src/escpos/constants.py +++ b/src/escpos/constants.py @@ -77,6 +77,12 @@ LINE_DISPLAY_CLOSE = ESC + b"\x3d\x01" SHEET_SLIP_MODE = ESC + b"\x63\x30\x04" # slip paper SHEET_ROLL_MODE = ESC + b"\x63\x30\x01" # paper roll +# Slip specific codes +SLIP_EJECT = ESC + b"\x4b\xc0" # Eject the slip or cheque +SLIP_SELECT = FS # Select the slip station as default station +SLIP_SET_WAIT_TIME = ESC + b"\x1b\x66" # Set timeout waiting for a slip/cheque to be inserted +SLIP_PRINT_AND_EJECT = b"\x0c" # Print the buffer and eject (after waiting for the paper to be inserted) + # Text format # TODO: Acquire the "ESC/POS Application Programming Guide for Paper Roll # Printers" and tidy up this stuff too. diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index c714d31..3e44f90 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -30,6 +30,11 @@ from .constants import ( QR_ECLEVEL_M, QR_ECLEVEL_H, QR_ECLEVEL_Q, + SHEET_ROLL_MODE, + SHEET_SLIP_MODE, + SLIP_PRINT_AND_EJECT, + SLIP_SELECT, + SLIP_EJECT ) from .constants import ( QR_MODEL_1, @@ -1015,6 +1020,42 @@ class Escpos(object): if status[0] & RT_MASK_PAPER == RT_MASK_PAPER: return 2 + """ + Select where to print to + + Print to the thermal printer by default (ROLL) or + print to the slip dot matrix printer if supported (SLIP) + """ + def target(self, type='ROLL'): + if type.upper() == 'ROLL': + self._raw(SHEET_ROLL_MODE) + elif type.upper() == 'SLIP': + self._raw(SHEET_SLIP_MODE) + else: + raise ValueError("Unsupported target") + + """ + Eject the slip/cheque + """ + def eject_slip(self): + self._raw(SLIP_EJECT) + + """ + Prints data from the buffer to the slip station and if the paper sensor is covered, + reverses the slip out the front of the printer far enough to be accessible to the operator. + The impact station opens the platen in all cases. + """ + def print_and_eject_slip(self): + self._raw(SLIP_PRINT_AND_EJECT) + + """ + Selects the Slip Station for all functions. + The receipt station is the default setting after the printer is initialized or + the Clear Printer (0x10) command is received + """ + def use_slip_only(self): + self._raw(SLIP_SELECT) + class EscposIO(object): """ESC/POS Printer IO object