From 1f427953a893076796c73b0f8773a1b654403d0c Mon Sep 17 00:00:00 2001 From: TAHRI Ahmed Date: Tue, 15 Nov 2016 16:24:44 +0100 Subject: [PATCH] Preliminary support of pos 'line display' printing --- src/escpos/constants.py | 5 +++++ src/escpos/escpos.py | 36 +++++++++++++++++++++++++++++++ test/test_function_linedisplay.py | 35 ++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 test/test_function_linedisplay.py diff --git a/src/escpos/constants.py b/src/escpos/constants.py index 821c143..4e61419 100644 --- a/src/escpos/constants.py +++ b/src/escpos/constants.py @@ -64,6 +64,11 @@ _PANEL_BUTTON = lambda n: ESC + b'c5' + six.int2byte(n) PANEL_BUTTON_ON = _PANEL_BUTTON(0) # enable all panel buttons PANEL_BUTTON_OFF = _PANEL_BUTTON(1) # disable all panel buttons +# Line display printing +LINE_DISPLAY_OPEN = ESC + b'\x3d\x02' +LINE_DISPLAY_CLEAR = ESC + b'\x40' +LINE_DISPLAY_CLOSE = ESC + b'\x3d\x01' + # Sheet modes SHEET_SLIP_MODE = ESC + b'\x63\x30\x04' # slip paper SHEET_ROLL_MODE = ESC + b'\x63\x30\x01' # paper roll diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index d6ff2bb..42c7305 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -26,6 +26,7 @@ from .constants import BARCODE_TXT_OFF, BARCODE_TXT_BTH, BARCODE_TXT_ABV, BARCOD from .constants import TXT_SIZE, TXT_NORMAL from .constants import SET_FONT from .constants import LINESPACING_FUNCS, LINESPACING_RESET +from .constants import LINE_DISPLAY_OPEN, LINE_DISPLAY_CLEAR, LINE_DISPLAY_CLOSE from .constants import CD_KICK_DEC_SEQUENCE, CD_KICK_5, CD_KICK_2, PAPER_FULL_CUT, PAPER_PART_CUT from .constants import HW_RESET, HW_SELECT, HW_INIT from .constants import CTL_VT, CTL_HT, CTL_CR, CTL_FF, CTL_LF, CTL_SET_HT, PANEL_BUTTON_OFF, PANEL_BUTTON_ON @@ -570,6 +571,41 @@ class Escpos(object): except: raise CashDrawerError() + def linedisplay_select(self, select_display=False): + """ Selects the line display or the printer + + This method is used for line displays that are daisy-chained between your computer and printer. + If you set `select_display` to true, only the display is selected and if you set it to false, + only the printer is selected. + + :param select_display: whether the display should be selected or the printer + :type select_display: bool + """ + if select_display: + self._raw(LINE_DISPLAY_OPEN) + else: + self._raw(LINE_DISPLAY_CLOSE) + + def linedisplay_clear(self): + """ Clears the line display and resets the cursor + + This method is used for line displays that are daisy-chained between your computer and printer. + """ + self._raw(LINE_DISPLAY_CLEAR) + + def linedisplay(self, text): + """ + Display text on a line display connected to your printer + + You should connect a line display to your printer. You can do this by daisy-chaining + the display between your computer and printer. + :param text: Text to display + """ + self.linedisplay_select(select_display=True) + self.linedisplay_clear() + self.text(text) + self.linedisplay_select(select_display=False) + def hw(self, hw): """ Hardware operations diff --git a/test/test_function_linedisplay.py b/test/test_function_linedisplay.py new file mode 100644 index 0000000..f5e92ca --- /dev/null +++ b/test/test_function_linedisplay.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +"""tests for line display + +:author: `Patrick Kanzler `_ +:organization: `python-escpos `_ +:copyright: Copyright (c) 2017 `python-escpos `_ +:license: MIT +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import escpos.printer as printer + + +def test_function_linedisplay_select_on(): + """test the linedisplay_select function (activate)""" + instance = printer.Dummy() + instance.linedisplay_select(select_display=True) + assert(instance.output == b'\x1B\x3D\x02') + +def test_function_linedisplay_select_off(): + """test the linedisplay_select function (deactivate)""" + instance = printer.Dummy() + instance.linedisplay_select(select_display=False) + assert(instance.output == b'\x1B\x3D\x01') + +def test_function_linedisplay_clear(): + """test the linedisplay_clear function""" + instance = printer.Dummy() + instance.linedisplay_clear() + assert(instance.output == b'\x1B\x40') +