From 279db655fdd91049b0b09f716724deaf2c83ccb4 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Fri, 3 Feb 2017 16:19:11 +0000 Subject: [PATCH 1/7] Handle cases when fullCut or partCut not available --- .gitignore | 5 +++++ capabilities-data | 2 +- src/escpos/escpos.py | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 932ff9b..346833d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,8 @@ src/escpos/version.py # testing temporary directories test/test-cli-output/ + +# vim swap files +*.swp +*.swn +*.swo diff --git a/capabilities-data b/capabilities-data index 31d2269..b6220ee 160000 --- a/capabilities-data +++ b/capabilities-data @@ -1 +1 @@ -Subproject commit 31d2269651d4d10ca51f59799ee4d05b4c4a1625 +Subproject commit b6220ee5c55b166f06d45a97f230312805b743b1 diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index 3e07fc0..a868daa 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -578,9 +578,11 @@ class Escpos(object): # Fix the size between last line and cut # TODO: handle this with a line feed self._raw(b"\n\n\n\n\n\n") - if mode.upper() == "PART": + + if mode.upper() == "PART" and self.profile.supports('paperPartCut'): self._raw(PAPER_PART_CUT) - else: # DEFAULT MODE: FULL CUT + elif mode.upper() != "PART" and self.profile.supports('paperFullCut'): + # DEFAULT MODE: FULL CUT self._raw(PAPER_FULL_CUT) def cashdraw(self, pin): From bdda1bbf9ccef27d6113186b49c089701d691378 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Mon, 6 Feb 2017 14:48:15 +0000 Subject: [PATCH 2/7] Refactored `cut` method. added `print_and_feed` method --- src/escpos/escpos.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index a868daa..dec66cf 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -564,7 +564,7 @@ class Escpos(object): self._raw(LINESPACING_FUNCS[divisor] + six.int2byte(spacing)) - def cut(self, mode=''): + def cut(self, mode='FULL'): """ Cut paper. Without any arguments the paper will be cut completely. With 'mode=PART' a partial cut will @@ -573,17 +573,25 @@ class Escpos(object): .. todo:: Check this function on TM-T88II. - :param mode: set to 'PART' for a partial cut + :param mode: set to 'PART' for a partial cut. default: 'FULL' + :raises ValueError: if mode not in ('FULL', 'PART') """ - # Fix the size between last line and cut - # TODO: handle this with a line feed - self._raw(b"\n\n\n\n\n\n") + self.print_and_feed(6) - if mode.upper() == "PART" and self.profile.supports('paperPartCut'): - self._raw(PAPER_PART_CUT) - elif mode.upper() != "PART" and self.profile.supports('paperFullCut'): - # DEFAULT MODE: FULL CUT - self._raw(PAPER_FULL_CUT) + mode = mode.upper() + if mode not in ('FULL', 'PART'): + raise ValueError("Mode must be one of ('FULL', 'PART')") + + if mode == "PART": + if self.profile.supports('paperPartCut'): + self._raw(PAPER_PART_CUT) + elif self.profile.supports('paperFullCut'): + self._raw(PAPER_FULL_CUT) + elif mode == "FULL": + if self.profile.supports('paperFullCut'): + self._raw(PAPER_FULL_CUT) + elif self.profile.supports('paperPartCut'): + self._raw(PAPER_PART_CUT) def cashdraw(self, pin): """ Send pulse to kick the cash drawer @@ -622,6 +630,20 @@ class Escpos(object): else: # DEFAULT: DOES NOTHING pass + def print_and_feed(self, n): + """ Print data in print buffer and feed *n* lines + + if n not in range (0, 255) then ValueError will be raised + + :param n: number of lines to feed. 0 <= n <= 255 + :raises ValueError: if not 0 <= n <= 255 + """ + if 0 <= n <= 255: + # ESC d n + self._raw(ESC + b"d" + six.binary_type(chr(n))) + else: + raise ValueError("n must be betwen 0 and 255") + def control(self, ctl, pos=4): """ Feed control sequences From 40c200f28d63e6ee5efcd3b613fb3a3f9adfef69 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Thu, 9 Feb 2017 09:44:57 +0000 Subject: [PATCH 3/7] Updated capabilities data to new version --- capabilities-data | 2 +- src/escpos/cli.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/capabilities-data b/capabilities-data index b6220ee..fd207aa 160000 --- a/capabilities-data +++ b/capabilities-data @@ -1 +1 @@ -Subproject commit b6220ee5c55b166f06d45a97f230312805b743b1 +Subproject commit fd207aa9debc9671405226598a086b282f9f3ad5 diff --git a/src/escpos/cli.py b/src/escpos/cli.py index dad2dfb..665e3b8 100644 --- a/src/escpos/cli.py +++ b/src/escpos/cli.py @@ -100,6 +100,12 @@ ESCPOS_COMMANDS = [ 'option_strings': ('--content',), 'help': 'Text to print as a qr code', 'required': True, + }, + { + 'option_strings': ('--size',), + 'help': 'QR code size (1-16) [default:3]', + 'required': False, + 'type': int, } ], }, From 8968e9463c1f7a37fa04a8734e40855f73bfaed9 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Thu, 9 Feb 2017 10:03:35 +0000 Subject: [PATCH 4/7] print_and_feed: py3 fix --- src/escpos/escpos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index dec66cf..406c3d5 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -640,7 +640,7 @@ class Escpos(object): """ if 0 <= n <= 255: # ESC d n - self._raw(ESC + b"d" + six.binary_type(chr(n))) + self._raw(ESC + b"d" + six.int2byte(n)) else: raise ValueError("n must be betwen 0 and 255") From 653b7df79c777f7c606adec1e4d4875591ae646c Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Thu, 9 Feb 2017 14:11:19 +0000 Subject: [PATCH 5/7] Bugfix in `control` method. print_and_feed default `n=1` --- src/escpos/escpos.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index 406c3d5..c238259 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -630,12 +630,12 @@ class Escpos(object): else: # DEFAULT: DOES NOTHING pass - def print_and_feed(self, n): + def print_and_feed(self, n=1): """ Print data in print buffer and feed *n* lines if n not in range (0, 255) then ValueError will be raised - :param n: number of lines to feed. 0 <= n <= 255 + :param n: number of n to feed. 0 <= n <= 255. default: 1 :raises ValueError: if not 0 <= n <= 255 """ if 0 <= n <= 255: @@ -658,11 +658,6 @@ class Escpos(object): :param pos: integer between 1 and 16, controls the horizontal tab position :raises: :py:exc:`~escpos.exceptions.TabPosError` """ - # Set tab positions - if not (1 <= pos <= 16): - raise TabPosError() - else: - self._raw(CTL_SET_HT + six.int2byte(pos)) # Set position if ctl.upper() == "LF": self._raw(CTL_LF) @@ -671,6 +666,12 @@ class Escpos(object): elif ctl.upper() == "CR": self._raw(CTL_CR) elif ctl.upper() == "HT": + if not (1 <= pos <= 16): + raise TabPosError() + else: + # Set tab positions + self._raw(CTL_SET_HT + six.int2byte(pos)) + self._raw(CTL_HT) elif ctl.upper() == "VT": self._raw(CTL_VT) From 9f1ac0de80d248b1a632efe71e207ef6cf02dc45 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Thu, 9 Feb 2017 14:39:37 +0000 Subject: [PATCH 6/7] Bugfix: incorrect `cut` commands [Documentation](http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf) --- src/escpos/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/escpos/constants.py b/src/escpos/constants.py index e3225f8..9df0595 100644 --- a/src/escpos/constants.py +++ b/src/escpos/constants.py @@ -53,8 +53,8 @@ CD_KICK_5 = _CASH_DRAWER(b'\x01', 50, 50) # Sends a pulse to pin 5 [] # Paper Cutter _CUT_PAPER = lambda m: GS + b'V' + m -PAPER_FULL_CUT = _CUT_PAPER(b'\x00') # Full cut paper -PAPER_PART_CUT = _CUT_PAPER(b'\x01') # Partial cut paper +PAPER_FULL_CUT = _CUT_PAPER(b'\x00\x30') # Full cut paper +PAPER_PART_CUT = _CUT_PAPER(b'\x01\x31') # Partial cut paper # Beep BEEP = b'\x07' From 396fa0d7befa291d60c04828bd95e3c4477816e9 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Wed, 29 Mar 2017 12:47:08 +0000 Subject: [PATCH 7/7] Revert "Bugfix: incorrect `cut` commands" It was incorrect commit This reverts commit 9f1ac0de80d248b1a632efe71e207ef6cf02dc45. --- src/escpos/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/escpos/constants.py b/src/escpos/constants.py index 9df0595..e3225f8 100644 --- a/src/escpos/constants.py +++ b/src/escpos/constants.py @@ -53,8 +53,8 @@ CD_KICK_5 = _CASH_DRAWER(b'\x01', 50, 50) # Sends a pulse to pin 5 [] # Paper Cutter _CUT_PAPER = lambda m: GS + b'V' + m -PAPER_FULL_CUT = _CUT_PAPER(b'\x00\x30') # Full cut paper -PAPER_PART_CUT = _CUT_PAPER(b'\x01\x31') # Partial cut paper +PAPER_FULL_CUT = _CUT_PAPER(b'\x00') # Full cut paper +PAPER_PART_CUT = _CUT_PAPER(b'\x01') # Partial cut paper # Beep BEEP = b'\x07'