From a242befc8e8671acad2a900de08a2246cc8481d5 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Tue, 03 May 2016 17:11:53 +0000 Subject: [PATCH] Add support for Code128 barcode (see test_form.py) --- axiohm.py | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/axiohm.py b/axiohm.py index ebeb2ee..b287b57 100644 --- a/axiohm.py +++ b/axiohm.py @@ -179,8 +179,8 @@ def setBarcodeTextPitch(self, pitch = PITCH_STANDARD): self.serial.write("\x1d\x66" + chr(pitch)) - def setBarcodeHeight(self, width): - self.serial.write("\x1d\x68" + chr(width)) + def setBarcodeHeight(self, height): + self.serial.write("\x1d\x68" + chr(height)) def setBarcodeHeightInches(self, inches = 1): if self.currentStation == self.STATION_SLIP: @@ -193,6 +193,9 @@ self.setBarcodeHeight(int(milimeters / 8.5)) else: self.setBarcodeHeight(int(milimeters / 8)) + + def setBarcodeWidth(self, width): + self.serial.write("\x1d\x77" + chr(width)) # FEEDING @@ -294,6 +297,17 @@ assert(type > 64) self.serial.write("\x1d\x6b" + chr(type) + chr(len(data)) + data) + def printCode128(self, bytelist): + assert 103 <= bytelist[0] <= 105 + assert bytelist[1] < 103 + + checksum = bytelist[0] + for i, item in enumerate(bytelist): + checksum = (checksum + i*item) % 103 + + bytelist.append(checksum) + self.printBarcode(self.BARCODE_CODE128, str(bytearray(bytelist))) + def printLinesRotatedCCW(self, lines, startingPosition = 0): maxLineLength = max([len(line) for line in lines]) lines = [line.ljust(maxLineLength, ' ') for line in lines] -- Gitblit v1.9.1