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) --- test_form.py | 49 ++++++++++++++++++++++++ axiohm.py | 18 ++++++++- 2 files changed, 65 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] diff --git a/test_form.py b/test_form.py new file mode 100755 index 0000000..0cbeb86 --- /dev/null +++ b/test_form.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from axiohm import Axiohm + +printer = Axiohm(port = '/dev/ttyS0', baudrate = 19200, xonxoff = True) + +print printer.getModel() +print printer.getStatus() + +slip = 0 + +printer.reset() + +if slip: + printer.waitForSlip() + printer.setBarcodeWidth(2) +else: + printer.selectReceipt() + printer.setPitch(printer.PITCH_COMPRESSED) + printer.setBarcodeWidth(3) + printer.cut() + +printer.setBarcodeHeight(32) + +printer.alignCenter() +printer.printLineUnicode(u"┌──────────────────────────────────────────────────────┐") +printer.printLineUnicode(u"│ POTWIERDZENIE NADANIA przesyłki poleconej nr │") +printer.printCode128([105, 102, 0, 75, 90, 07, 73, 12, 34, 56, 78, 90]) +printer.feedDots(5) +printer.printLineUnicode(u"│ (00) 7 5900773 1 234567890 │") +printer.printLineUnicode(u"├───────────────────────────────┐ │") +printer.printLineUnicode(u"│ NADAWCA: │ Opłata ... zł ... gr │") +printer.printLineUnicode(u"│ Test Testowy │ Masa ... kg ... g │") +printer.printLineUnicode(u"│ ul. Testowa 1 │ GABARYT A[ ] B[ ] │") +printer.printLineUnicode(u"│ 01-001 Test │ Priorytetowa: [ ] │") +printer.printLineUnicode(u"│ │ Potw. odbioru: [ ] │") +printer.printLineUnicode(u"│ │ │") +printer.printLineUnicode(u"│ ADRESAT: │ │") +printer.printLineUnicode(u"│ Test Testowy │ ( ) │") +printer.printLineUnicode(u"│ ul. Testowa 1 │ │") +printer.printLineUnicode(u"│ 01-001 Test │ │") +printer.printLineUnicode(u"│ │ Podpis przyjmującego │") +printer.printLineUnicode(u"└───────────────────────────────┴──────────────────────┘") + +if slip: + printer.ejectSlip() +else: + printer.cut() -- Gitblit v1.9.1