Axiohm A758 helper library for Python
Jacek Kowalski
2016-05-03 a242befc8e8671acad2a900de08a2246cc8481d5
Add support for Code128 barcode (see test_form.py)
1 files added
1 files modified
67 ■■■■■ changed files
axiohm.py 18 ●●●● patch | view | raw | blame | history
test_form.py 49 ●●●●● patch | view | raw | blame | history
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]
test_form.py
New file
@@ -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()