From 60bc6b7d5c377cb5644224fe9ea7edfd28167e90 Mon Sep 17 00:00:00 2001 From: davisgoglin Date: Sun, 6 Mar 2016 20:04:58 -0800 Subject: [PATCH 01/10] Add barcode types for function type B, reorganize existing types --- escpos/constants.py | 72 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/escpos/constants.py b/escpos/constants.py index d1835a4..413f53d 100644 --- a/escpos/constants.py +++ b/escpos/constants.py @@ -126,17 +126,71 @@ BARCODE_WIDTH = GS + 'w' # Barcode Width [2-6] #NOTE: This isn't actually an ESC/POS command. It's the common prefix to the # two "print bar code" commands: -# - "GS k NUL" -# - "GS k " +# - Type A: "GS k NUL" +# - TYPE B: "GS k " # The latter command supports more barcode types _SET_BARCODE_TYPE = lambda m: GS + 'k' + m -BARCODE_UPC_A = _SET_BARCODE_TYPE('\x00') # Barcode type UPC-A -BARCODE_UPC_E = _SET_BARCODE_TYPE('\x01') # Barcode type UPC-E -BARCODE_EAN13 = _SET_BARCODE_TYPE('\x02') # Barcode type EAN13 -BARCODE_EAN8 = _SET_BARCODE_TYPE('\x03') # Barcode type EAN8 -BARCODE_CODE39 = _SET_BARCODE_TYPE('\x04') # Barcode type CODE39 -BARCODE_ITF = _SET_BARCODE_TYPE('\x05') # Barcode type ITF -BARCODE_NW7 = _SET_BARCODE_TYPE('\x06') # Barcode type NW7 + +# Barcodes for type A +BARCODE_A_UPC_A = _SET_BARCODE_TYPE('\x00') # Barcode type UPC-A +BARCODE_A_UPC_E = _SET_BARCODE_TYPE('\x01') # Barcode type UPC-E +BARCODE_A_EAN13 = _SET_BARCODE_TYPE('\x02') # Barcode type EAN13 +BARCODE_A_EAN8 = _SET_BARCODE_TYPE('\x03') # Barcode type EAN8 +BARCODE_A_CODE39 = _SET_BARCODE_TYPE('\x04') # Barcode type CODE39 +BARCODE_A_ITF = _SET_BARCODE_TYPE('\x05') # Barcode type ITF +BARCODE_A_NW7 = _SET_BARCODE_TYPE('\x06') # Barcode type NW7 + +# Barcodes for type B +BARCODE_B_UPC_A = _SET_BARCODE_TYPE('\x65') # Barcode type UPC-A +BARCODE_B_UPC_E = _SET_BARCODE_TYPE('\x66') # Barcode type UPC-E +BARCODE_B_EAN13 = _SET_BARCODE_TYPE('\x67') # Barcode type EAN13 +BARCODE_B_EAN8 = _SET_BARCODE_TYPE('\x68') # Barcode type EAN8 +BARCODE_B_CODE39 = _SET_BARCODE_TYPE('\x69') # Barcode type CODE39 +BARCODE_B_ITF = _SET_BARCODE_TYPE('\x70') # Barcode type ITF +BARCODE_B_NW7 = _SET_BARCODE_TYPE('\x71') # Barcode type NW7 +BARCODE_B_CODE93 = _SET_BARCODE_TYPE('\x72') # Barcode type CODE93 +BARCODE_B_CODE128 = _SET_BARCODE_TYPE('\x73') # Barcode type CODE128 +BARCODE_B_GS1_128 = _SET_BARCODE_TYPE('\x74') # Barcode type GS1_128 +BARCODE_B_GS1_DATABAR_OMNI = _SET_BARCODE_TYPE('\x75') # Barcode type GS1 DataBar Omnidirectional +BARCODE_B_GS1_DATABAR_TRUNC = _SET_BARCODE_TYPE('\x76') # Barcode type GS1 DataBar Truncated +BARCODE_B_GS1_DATABAR_LIM = _SET_BARCODE_TYPE('\x77') # Barcode type GS1 DataBar Limited +BARCODE_B_GS1_DATABAR_EXP = _SET_BARCODE_TYPE('\x78') # Barcode type GS1 DataBar Expanded + +# Constants to be used when the user is calling the function. All uppercase. +BARCODE_TYPE_A = { + 'UPC-A': BARCODE_A_UPC_A, + 'UPC-E': BARCODE_A_UPC_E, + 'EAN13': BARCODE_A_EAN13, + 'EAN8': BARCODE_A_EAN8, + 'CODE39': BARCODE_A_CODE39, + 'ITF': BARCODE_A_ITF, + 'NW7': BARCODE_A_NW7, + 'CODEBAR': BARCODE_A_NW7, +} + +BARCODE_TYPE_B = { + 'UPC-A': BARCODE_B_UPC_A, + 'UPC-E': BARCODE_B_UPC_E, + 'EAN13': BARCODE_B_EAN13, + 'EAN8': BARCODE_B_EAN8, + 'CODE39': BARCODE_B_CODE39, + 'ITF': BARCODE_B_ITF, + 'NW7': BARCODE_B_NW7, + 'CODEBAR': BARCODE_B_NW7, + 'CODE93': BARCODE_B_CODE93, + 'CODE128': BARCODE_B_CODE128, + 'GS1_128': BARCODE_B_GS1_128, + 'GS1 DATABAR OMNIDIRECTIONAL': BARCODE_B_GS1_DATABAR_OMNI, + 'GS1 DATABAR TRUNCATED': BARCODE_B_GS1_DATABAR_TRUNC, + 'GS1 DATABAR LIMITED': BARCODE_B_GS1_DATABAR_LIM, + 'GS1 DATABAR EXPANDED': BARCODE_B_GS1_DATABAR_EXP, +} + +BARCODE_TYPES = { + 'A': BARCODE_TYPE_A, + 'B': BARCODE_TYPE_B, +} + # Image format # NOTE: _PRINT_RASTER_IMG is the obsolete ESC/POS "print raster bit image" From 5c49e0103ce5d0629e81e5846e05e06eb20e14f7 Mon Sep 17 00:00:00 2001 From: davisgoglin Date: Sun, 6 Mar 2016 20:06:05 -0800 Subject: [PATCH 02/10] Update barcode printing to allow for barcode function type B --- escpos/escpos.py | 53 ++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index 8944633..1aed8ad 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -314,12 +314,13 @@ class Escpos(object): else: raise CharCodeError() - def barcode(self, code, bc, height=64, width=3, pos="BELOW", font="A", align_ct=True): + def barcode(self, code, bc, height=64, width=3, pos="BELOW", font="A", align_ct=True, function_type="A"): """ Print Barcode This method allows to print barcodes. The rendering of the barcode is done by the printer and therefore has to be supported by the unit. Currently you have to check manually whether your barcode text is correct. Uncorrect - barcodes may lead to unexpected printer behaviour. + barcodes may lead to unexpected printer behaviour. There are two forms of the barcode function. Type A is + default but has fewer barcodes, while type B has some more to choose from. .. todo:: Add a method to check barcode codes. Alternatively or as an addition write explanations about each barcode-type. Research whether the check digits can be computed autmatically. @@ -340,7 +341,7 @@ class Escpos(object): be of help if the printer does not support types that others do.) :param code: alphanumeric data to be printed as bar code - :param bc: barcode format, possible values are: + :param bc: barcode format, possible values are for type A are: * UPC-A * UPC-E @@ -350,6 +351,17 @@ class Escpos(object): * ITF * NW7 + Possible values for type B: + + * All types from function type A + * CODE93 + * CODE128 + * GS1-128 + * GS1 DataBar Omnidirectional + * GS1 DataBar Truncated + * GS1 DataBar Limited + * GS1 DataBar Expanded + If none is specified, the method raises :py:exc:`~escpos.exceptions.BarcodeTypeError`. :param height: barcode height, has to be between 1 and 255 *default*: 64 @@ -373,6 +385,10 @@ class Escpos(object): issued. :type align_ct: bool + :param function_type: Choose between ESCPOS function type A or B, depending on printer support and desired + barcode. + *default*: A + :raises: :py:exc:`~escpos.exceptions.BarcodeSizeError`, :py:exc:`~escpos.exceptions.BarcodeTypeError`, :py:exc:`~escpos.exceptions.BarcodeCodeError` @@ -404,23 +420,20 @@ class Escpos(object): self._raw(BARCODE_TXT_ABV) else: # DEFAULT POSITION: BELOW self._raw(BARCODE_TXT_BLW) - # Type - if bc.upper() == "UPC-A": - self._raw(BARCODE_UPC_A) - elif bc.upper() == "UPC-E": - self._raw(BARCODE_UPC_E) - elif bc.upper() == "EAN13": - self._raw(BARCODE_EAN13) - elif bc.upper() == "EAN8": - self._raw(BARCODE_EAN8) - elif bc.upper() == "CODE39": - self._raw(BARCODE_CODE39) - elif bc.upper() == "ITF": - self._raw(BARCODE_ITF) - elif bc.upper() in ("NW7", "CODABAR"): - self._raw(BARCODE_NW7) - else: - raise BarcodeTypeError(bc) + + bc_types = BARCODE_TYPES[function_type] + if bc.upper() not in bc_types.keys(): + # TODO: Raise a better error, or fix the message of this error type + raise BarcodeTypeError("Barcode type {bc} not valid for barcode function type {function_type}".format( + bc=bc, + function_type=function_type, + )) + + self._raw(bc_types[bc.upper()]) + + if function_type.upper() == "B": + self._raw(chr(len(code))) + # Print Code if code: self._raw(code) From d9ffb030899a7ce7de87fad9c1f7ab5d6302b6e6 Mon Sep 17 00:00:00 2001 From: davisgoglin Date: Sun, 6 Mar 2016 20:25:16 -0800 Subject: [PATCH 03/10] Update documentation for barcode function type B --- doc/user/methods.rst | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/user/methods.rst b/doc/user/methods.rst index 247d9cc..055c3b0 100644 --- a/doc/user/methods.rst +++ b/doc/user/methods.rst @@ -36,7 +36,7 @@ barcode("code", "barcode\_type", width, height, "position", "font") Prints a barcode. * ``code`` is an alphanumeric code to be printed as bar code -* ``barcode_type`` must be one of the following type of codes: +* ``barcode_type`` must be one of the following type of codes for function type A: * UPC-A * UPC-E @@ -45,7 +45,19 @@ Prints a barcode. * CODE39 * ITF * NW7 - + + And for function type B: + + * Any type above + * CODE93 + * CODE128 + * GS1-128 + * GS1 DataBar Omnidirectional + * GS1 DataBar Truncated + * GS1 DataBar Limited + * GS1 DataBar Expanded + + * ``width`` is a numeric value in the range between (1,255) *Default:* 64 * ``height`` is a numeric value in the range between (2,6) *Default:* 3 * ``position`` is where to place the code around the bars, could be one of the following values: @@ -58,7 +70,14 @@ Prints a barcode. * ``font`` is one of the 2 type of fonts, values could be: * A - * B > *Default:* A Raises ``BarcodeTypeError``, ``BarcodeSizeError``, ``BarcodeCodeError`` exceptions. + * B > *Default:* A + +* ``fuction_type`` chooses between ESCPOS function type A or B. A is default, B has more barcode options. Choose which one based upon your printer support and require barcode. + + * A + * B > *Default* A + +* Raises ``BarcodeTypeError``, ``BarcodeSizeError``, ``BarcodeCodeError`` exceptions. text("text") ^^^^^^^^^^^^ From 250455ae23cc703a061d41697463a2733cf67f64 Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Mon, 7 Mar 2016 16:20:04 -0800 Subject: [PATCH 04/10] Add null terminator when printing barcode of type A, issue #58 --- escpos/escpos.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/escpos/escpos.py b/escpos/escpos.py index 1aed8ad..f18b169 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -440,6 +440,9 @@ class Escpos(object): else: raise BarcodeCodeError() + if function_type.upper() == "A": + self._raw("\x00") + def text(self, txt): """ Print alpha-numeric text From d888a39b6f8b964b7bec3bc08fc0f67fd18d618f Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Mon, 7 Mar 2016 16:22:13 -0800 Subject: [PATCH 05/10] Fix typo, CODEBAR -> CODABAR --- escpos/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/escpos/constants.py b/escpos/constants.py index 413f53d..ca6efb7 100644 --- a/escpos/constants.py +++ b/escpos/constants.py @@ -165,7 +165,7 @@ BARCODE_TYPE_A = { 'CODE39': BARCODE_A_CODE39, 'ITF': BARCODE_A_ITF, 'NW7': BARCODE_A_NW7, - 'CODEBAR': BARCODE_A_NW7, + 'CODABAR': BARCODE_A_NW7, } BARCODE_TYPE_B = { @@ -176,7 +176,7 @@ BARCODE_TYPE_B = { 'CODE39': BARCODE_B_CODE39, 'ITF': BARCODE_B_ITF, 'NW7': BARCODE_B_NW7, - 'CODEBAR': BARCODE_B_NW7, + 'CODABAR': BARCODE_B_NW7, 'CODE93': BARCODE_B_CODE93, 'CODE128': BARCODE_B_CODE128, 'GS1_128': BARCODE_B_GS1_128, From 7f921c667b3c0b6c08002e6d6309f5c618bb8cd7 Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Mon, 7 Mar 2016 17:39:12 -0800 Subject: [PATCH 06/10] Fix barcode type B codes --- escpos/constants.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/escpos/constants.py b/escpos/constants.py index ca6efb7..9315395 100644 --- a/escpos/constants.py +++ b/escpos/constants.py @@ -132,29 +132,29 @@ BARCODE_WIDTH = GS + 'w' # Barcode Width [2-6] _SET_BARCODE_TYPE = lambda m: GS + 'k' + m # Barcodes for type A -BARCODE_A_UPC_A = _SET_BARCODE_TYPE('\x00') # Barcode type UPC-A -BARCODE_A_UPC_E = _SET_BARCODE_TYPE('\x01') # Barcode type UPC-E -BARCODE_A_EAN13 = _SET_BARCODE_TYPE('\x02') # Barcode type EAN13 -BARCODE_A_EAN8 = _SET_BARCODE_TYPE('\x03') # Barcode type EAN8 -BARCODE_A_CODE39 = _SET_BARCODE_TYPE('\x04') # Barcode type CODE39 -BARCODE_A_ITF = _SET_BARCODE_TYPE('\x05') # Barcode type ITF -BARCODE_A_NW7 = _SET_BARCODE_TYPE('\x06') # Barcode type NW7 +BARCODE_A_UPC_A = _SET_BARCODE_TYPE(chr(0)) # Barcode type UPC-A +BARCODE_A_UPC_E = _SET_BARCODE_TYPE(chr(1)) # Barcode type UPC-E +BARCODE_A_EAN13 = _SET_BARCODE_TYPE(chr(2)) # Barcode type EAN13 +BARCODE_A_EAN8 = _SET_BARCODE_TYPE(chr(3)) # Barcode type EAN8 +BARCODE_A_CODE39 = _SET_BARCODE_TYPE(chr(4)) # Barcode type CODE39 +BARCODE_A_ITF = _SET_BARCODE_TYPE(chr(5)) # Barcode type ITF +BARCODE_A_NW7 = _SET_BARCODE_TYPE(chr(6)) # Barcode type NW7 # Barcodes for type B -BARCODE_B_UPC_A = _SET_BARCODE_TYPE('\x65') # Barcode type UPC-A -BARCODE_B_UPC_E = _SET_BARCODE_TYPE('\x66') # Barcode type UPC-E -BARCODE_B_EAN13 = _SET_BARCODE_TYPE('\x67') # Barcode type EAN13 -BARCODE_B_EAN8 = _SET_BARCODE_TYPE('\x68') # Barcode type EAN8 -BARCODE_B_CODE39 = _SET_BARCODE_TYPE('\x69') # Barcode type CODE39 -BARCODE_B_ITF = _SET_BARCODE_TYPE('\x70') # Barcode type ITF -BARCODE_B_NW7 = _SET_BARCODE_TYPE('\x71') # Barcode type NW7 -BARCODE_B_CODE93 = _SET_BARCODE_TYPE('\x72') # Barcode type CODE93 -BARCODE_B_CODE128 = _SET_BARCODE_TYPE('\x73') # Barcode type CODE128 -BARCODE_B_GS1_128 = _SET_BARCODE_TYPE('\x74') # Barcode type GS1_128 -BARCODE_B_GS1_DATABAR_OMNI = _SET_BARCODE_TYPE('\x75') # Barcode type GS1 DataBar Omnidirectional -BARCODE_B_GS1_DATABAR_TRUNC = _SET_BARCODE_TYPE('\x76') # Barcode type GS1 DataBar Truncated -BARCODE_B_GS1_DATABAR_LIM = _SET_BARCODE_TYPE('\x77') # Barcode type GS1 DataBar Limited -BARCODE_B_GS1_DATABAR_EXP = _SET_BARCODE_TYPE('\x78') # Barcode type GS1 DataBar Expanded +BARCODE_B_UPC_A = _SET_BARCODE_TYPE(chr(65)) # Barcode type UPC-A +BARCODE_B_UPC_E = _SET_BARCODE_TYPE(chr(66)) # Barcode type UPC-E +BARCODE_B_EAN13 = _SET_BARCODE_TYPE(chr(67)) # Barcode type EAN13 +BARCODE_B_EAN8 = _SET_BARCODE_TYPE(chr(68)) # Barcode type EAN8 +BARCODE_B_CODE39 = _SET_BARCODE_TYPE(chr(69)) # Barcode type CODE39 +BARCODE_B_ITF = _SET_BARCODE_TYPE(chr(70)) # Barcode type ITF +BARCODE_B_NW7 = _SET_BARCODE_TYPE(chr(71)) # Barcode type NW7 +BARCODE_B_CODE93 = _SET_BARCODE_TYPE(chr(72)) # Barcode type CODE93 +BARCODE_B_CODE128 = _SET_BARCODE_TYPE(chr(73)) # Barcode type CODE128 +BARCODE_B_GS1_128 = _SET_BARCODE_TYPE(chr(74)) # Barcode type GS1_128 +BARCODE_B_GS1_DATABAR_OMNI = _SET_BARCODE_TYPE(chr(75)) # Barcode type GS1 DataBar Omnidirectional +BARCODE_B_GS1_DATABAR_TRUNC = _SET_BARCODE_TYPE(chr(76)) # Barcode type GS1 DataBar Truncated +BARCODE_B_GS1_DATABAR_LIM = _SET_BARCODE_TYPE(chr(77)) # Barcode type GS1 DataBar Limited +BARCODE_B_GS1_DATABAR_EXP = _SET_BARCODE_TYPE(chr(78)) # Barcode type GS1 DataBar Expanded # Constants to be used when the user is calling the function. All uppercase. BARCODE_TYPE_A = { From 68a9dcc47becf229187a3a90d1fe386ad55c5992 Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Tue, 8 Mar 2016 08:12:51 -0800 Subject: [PATCH 07/10] Typo fix GS_128 -> GS-128 --- escpos/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/escpos/constants.py b/escpos/constants.py index 9315395..dcac0d3 100644 --- a/escpos/constants.py +++ b/escpos/constants.py @@ -150,7 +150,7 @@ BARCODE_B_ITF = _SET_BARCODE_TYPE(chr(70)) # Barcode type ITF BARCODE_B_NW7 = _SET_BARCODE_TYPE(chr(71)) # Barcode type NW7 BARCODE_B_CODE93 = _SET_BARCODE_TYPE(chr(72)) # Barcode type CODE93 BARCODE_B_CODE128 = _SET_BARCODE_TYPE(chr(73)) # Barcode type CODE128 -BARCODE_B_GS1_128 = _SET_BARCODE_TYPE(chr(74)) # Barcode type GS1_128 +BARCODE_B_GS1_128 = _SET_BARCODE_TYPE(chr(74)) # Barcode type GS1-128 BARCODE_B_GS1_DATABAR_OMNI = _SET_BARCODE_TYPE(chr(75)) # Barcode type GS1 DataBar Omnidirectional BARCODE_B_GS1_DATABAR_TRUNC = _SET_BARCODE_TYPE(chr(76)) # Barcode type GS1 DataBar Truncated BARCODE_B_GS1_DATABAR_LIM = _SET_BARCODE_TYPE(chr(77)) # Barcode type GS1 DataBar Limited @@ -179,7 +179,7 @@ BARCODE_TYPE_B = { 'CODABAR': BARCODE_B_NW7, 'CODE93': BARCODE_B_CODE93, 'CODE128': BARCODE_B_CODE128, - 'GS1_128': BARCODE_B_GS1_128, + 'GS1-128': BARCODE_B_GS1_128, 'GS1 DATABAR OMNIDIRECTIONAL': BARCODE_B_GS1_DATABAR_OMNI, 'GS1 DATABAR TRUNCATED': BARCODE_B_GS1_DATABAR_TRUNC, 'GS1 DATABAR LIMITED': BARCODE_B_GS1_DATABAR_LIM, From dbb00812874175423637aeb6d60f09a688bba605 Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Tue, 8 Mar 2016 08:45:49 -0800 Subject: [PATCH 08/10] Split CODE128 into it's character sets --- escpos/constants.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/escpos/constants.py b/escpos/constants.py index dcac0d3..cf11333 100644 --- a/escpos/constants.py +++ b/escpos/constants.py @@ -149,7 +149,9 @@ BARCODE_B_CODE39 = _SET_BARCODE_TYPE(chr(69)) # Barcode type CODE39 BARCODE_B_ITF = _SET_BARCODE_TYPE(chr(70)) # Barcode type ITF BARCODE_B_NW7 = _SET_BARCODE_TYPE(chr(71)) # Barcode type NW7 BARCODE_B_CODE93 = _SET_BARCODE_TYPE(chr(72)) # Barcode type CODE93 -BARCODE_B_CODE128 = _SET_BARCODE_TYPE(chr(73)) # Barcode type CODE128 +BARCODE_B_CODE128A = _SET_BARCODE_TYPE(chr(73) + '{A') # Barcode type CODE128 character set A +BARCODE_B_CODE128B = _SET_BARCODE_TYPE(chr(73) + '{B') # Barcode type CODE128 character set B +BARCODE_B_CODE128C = _SET_BARCODE_TYPE(chr(73) + '{C') # Barcode type CODE128 character set C BARCODE_B_GS1_128 = _SET_BARCODE_TYPE(chr(74)) # Barcode type GS1-128 BARCODE_B_GS1_DATABAR_OMNI = _SET_BARCODE_TYPE(chr(75)) # Barcode type GS1 DataBar Omnidirectional BARCODE_B_GS1_DATABAR_TRUNC = _SET_BARCODE_TYPE(chr(76)) # Barcode type GS1 DataBar Truncated @@ -178,7 +180,9 @@ BARCODE_TYPE_B = { 'NW7': BARCODE_B_NW7, 'CODABAR': BARCODE_B_NW7, 'CODE93': BARCODE_B_CODE93, - 'CODE128': BARCODE_B_CODE128, + 'CODE128A': BARCODE_B_CODE128A, + 'CODE128B': BARCODE_B_CODE128B, + 'CODE128C': BARCODE_B_CODE128C, 'GS1-128': BARCODE_B_GS1_128, 'GS1 DATABAR OMNIDIRECTIONAL': BARCODE_B_GS1_DATABAR_OMNI, 'GS1 DATABAR TRUNCATED': BARCODE_B_GS1_DATABAR_TRUNC, From 39d1c1d587c48a82b1c73a8c2e5cd7c503f8d14d Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Tue, 8 Mar 2016 09:16:35 -0800 Subject: [PATCH 09/10] Format barcode types --- escpos/constants.py | 82 ++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 53 deletions(-) diff --git a/escpos/constants.py b/escpos/constants.py index cf11333..4274fbe 100644 --- a/escpos/constants.py +++ b/escpos/constants.py @@ -131,63 +131,39 @@ BARCODE_WIDTH = GS + 'w' # Barcode Width [2-6] # The latter command supports more barcode types _SET_BARCODE_TYPE = lambda m: GS + 'k' + m -# Barcodes for type A -BARCODE_A_UPC_A = _SET_BARCODE_TYPE(chr(0)) # Barcode type UPC-A -BARCODE_A_UPC_E = _SET_BARCODE_TYPE(chr(1)) # Barcode type UPC-E -BARCODE_A_EAN13 = _SET_BARCODE_TYPE(chr(2)) # Barcode type EAN13 -BARCODE_A_EAN8 = _SET_BARCODE_TYPE(chr(3)) # Barcode type EAN8 -BARCODE_A_CODE39 = _SET_BARCODE_TYPE(chr(4)) # Barcode type CODE39 -BARCODE_A_ITF = _SET_BARCODE_TYPE(chr(5)) # Barcode type ITF -BARCODE_A_NW7 = _SET_BARCODE_TYPE(chr(6)) # Barcode type NW7 - -# Barcodes for type B -BARCODE_B_UPC_A = _SET_BARCODE_TYPE(chr(65)) # Barcode type UPC-A -BARCODE_B_UPC_E = _SET_BARCODE_TYPE(chr(66)) # Barcode type UPC-E -BARCODE_B_EAN13 = _SET_BARCODE_TYPE(chr(67)) # Barcode type EAN13 -BARCODE_B_EAN8 = _SET_BARCODE_TYPE(chr(68)) # Barcode type EAN8 -BARCODE_B_CODE39 = _SET_BARCODE_TYPE(chr(69)) # Barcode type CODE39 -BARCODE_B_ITF = _SET_BARCODE_TYPE(chr(70)) # Barcode type ITF -BARCODE_B_NW7 = _SET_BARCODE_TYPE(chr(71)) # Barcode type NW7 -BARCODE_B_CODE93 = _SET_BARCODE_TYPE(chr(72)) # Barcode type CODE93 -BARCODE_B_CODE128A = _SET_BARCODE_TYPE(chr(73) + '{A') # Barcode type CODE128 character set A -BARCODE_B_CODE128B = _SET_BARCODE_TYPE(chr(73) + '{B') # Barcode type CODE128 character set B -BARCODE_B_CODE128C = _SET_BARCODE_TYPE(chr(73) + '{C') # Barcode type CODE128 character set C -BARCODE_B_GS1_128 = _SET_BARCODE_TYPE(chr(74)) # Barcode type GS1-128 -BARCODE_B_GS1_DATABAR_OMNI = _SET_BARCODE_TYPE(chr(75)) # Barcode type GS1 DataBar Omnidirectional -BARCODE_B_GS1_DATABAR_TRUNC = _SET_BARCODE_TYPE(chr(76)) # Barcode type GS1 DataBar Truncated -BARCODE_B_GS1_DATABAR_LIM = _SET_BARCODE_TYPE(chr(77)) # Barcode type GS1 DataBar Limited -BARCODE_B_GS1_DATABAR_EXP = _SET_BARCODE_TYPE(chr(78)) # Barcode type GS1 DataBar Expanded - -# Constants to be used when the user is calling the function. All uppercase. +# Barcodes for printing function type A BARCODE_TYPE_A = { - 'UPC-A': BARCODE_A_UPC_A, - 'UPC-E': BARCODE_A_UPC_E, - 'EAN13': BARCODE_A_EAN13, - 'EAN8': BARCODE_A_EAN8, - 'CODE39': BARCODE_A_CODE39, - 'ITF': BARCODE_A_ITF, - 'NW7': BARCODE_A_NW7, - 'CODABAR': BARCODE_A_NW7, + 'UPC-A': _SET_BARCODE_TYPE(chr(0)), + 'UPC-E': _SET_BARCODE_TYPE(chr(1)), + 'EAN13': _SET_BARCODE_TYPE(chr(2)), + 'EAN8': _SET_BARCODE_TYPE(chr(3)), + 'CODE39': _SET_BARCODE_TYPE(chr(4)), + 'ITF': _SET_BARCODE_TYPE(chr(5)), + 'NW7': _SET_BARCODE_TYPE(chr(6)), + 'CODABAR': _SET_BARCODE_TYPE(chr(6)), # Same as NW7 } +# Barcodes for printing function type B +# The first 8 are the same barcodes as type A BARCODE_TYPE_B = { - 'UPC-A': BARCODE_B_UPC_A, - 'UPC-E': BARCODE_B_UPC_E, - 'EAN13': BARCODE_B_EAN13, - 'EAN8': BARCODE_B_EAN8, - 'CODE39': BARCODE_B_CODE39, - 'ITF': BARCODE_B_ITF, - 'NW7': BARCODE_B_NW7, - 'CODABAR': BARCODE_B_NW7, - 'CODE93': BARCODE_B_CODE93, - 'CODE128A': BARCODE_B_CODE128A, - 'CODE128B': BARCODE_B_CODE128B, - 'CODE128C': BARCODE_B_CODE128C, - 'GS1-128': BARCODE_B_GS1_128, - 'GS1 DATABAR OMNIDIRECTIONAL': BARCODE_B_GS1_DATABAR_OMNI, - 'GS1 DATABAR TRUNCATED': BARCODE_B_GS1_DATABAR_TRUNC, - 'GS1 DATABAR LIMITED': BARCODE_B_GS1_DATABAR_LIM, - 'GS1 DATABAR EXPANDED': BARCODE_B_GS1_DATABAR_EXP, + 'UPC-A': _SET_BARCODE_TYPE(chr(65)), + 'UPC-E': _SET_BARCODE_TYPE(chr(66)), + 'EAN13': _SET_BARCODE_TYPE(chr(67)), + 'EAN8': _SET_BARCODE_TYPE(chr(68)), + 'CODE39': _SET_BARCODE_TYPE(chr(69)), + 'ITF': _SET_BARCODE_TYPE(chr(70)), + 'NW7': _SET_BARCODE_TYPE(chr(71)), + 'CODABAR': _SET_BARCODE_TYPE(chr(71)), # Same as NW7 + 'CODE93': _SET_BARCODE_TYPE(chr(72)), + # These are all the same barcode, but using different charcter sets + 'CODE128A': _SET_BARCODE_TYPE(chr(73) + '{A'), # CODE128 character set A + 'CODE128B': _SET_BARCODE_TYPE(chr(73) + '{B'), # CODE128 character set B + 'CODE128C': _SET_BARCODE_TYPE(chr(73) + '{C'), # CODE128 character set C + 'GS1-128': _SET_BARCODE_TYPE(chr(74)), + 'GS1 DATABAR OMNIDIRECTIONAL': _SET_BARCODE_TYPE(chr(75)), + 'GS1 DATABAR TRUNCATED': _SET_BARCODE_TYPE(chr(76)), + 'GS1 DATABAR LIMITED': _SET_BARCODE_TYPE(chr(77)), + 'GS1 DATABAR EXPANDED': _SET_BARCODE_TYPE(chr(78)), } BARCODE_TYPES = { From 9d12c7faab60e97273a5e069f23bba430d5256f6 Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Tue, 8 Mar 2016 09:17:47 -0800 Subject: [PATCH 10/10] Add missing .upper() for function type --- escpos/escpos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index f18b169..62c90b1 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -421,7 +421,7 @@ class Escpos(object): else: # DEFAULT POSITION: BELOW self._raw(BARCODE_TXT_BLW) - bc_types = BARCODE_TYPES[function_type] + bc_types = BARCODE_TYPES[function_type.upper()] if bc.upper() not in bc_types.keys(): # TODO: Raise a better error, or fix the message of this error type raise BarcodeTypeError("Barcode type {bc} not valid for barcode function type {function_type}".format(