Escpos Thermal ZJ-58 Python Code128 Barcode print shows nothing

Viewed 623
from escpos.printer import Usb

p = Usb(0x0416, 0x5011, 0, 0x81, 0x03)
p.text("=================\n")
#p.image("./barcode/barcode.png")
#p.barcode('1324354657687', 'EAN13', 64, 2, '', './fonts/code128.ttf')
### barcode(code, bc, width, height, pos, font)
p.barcode("{B012ABCDabcd", "CODE128", function_type="B")
# Print QR Code
#p.qr("You can readme from your smartphone")
#p.cut()
#print(p.control('LF', 16))
#print(p.device)

I tried to print code128 and ean barcodes. I only got texts like;

@1324354657687

@I{B012ABCDabcd

. I've tried to add font file (which was not useful), to change code type and some other unuseful things. I researched the documents and manuals from internet. I could print text and image.

I use this https://github.com/escpos/python-escpos

The printer I use: Zijiang thermal ZJ-5890

Any idea why I get only letters but not barcode?

1 Answers

The library you presented does not support Code128 barcodes when you look at the source code.
python-escpos/escpos/escpos.py#L150

def barcode(self, code, bc, width, height, pos, font):
    """ Print Barcode """
    ... Omitted on the way ...
    # 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() == "NW7":
        self._raw(BARCODE_NW7)
    else:
        raise BarcodeTypeError()
    # Print Code

There seems to be a library with the same name, so why not try using it?
python-escpos 2.2.0
python-escpos/python-escpos
python-escpos - Python library to manipulate ESC/POS Printers
Printing Barcodes

Escpos.barcode(code, bc, height=64, width=3, pos='BELOW', font='A', align_ct=True, function_type=None, check=True)

Parameters

  • bc –
    Possible values for type B:
    • CODE128
    • GS1-128

CODE128
Code128 barcodes need a certain format. For now the user has to make sure that the payload is correct. For alphanumeric CODE128 you have to preface your payload with {B.

from escpos.printer import Dummy, Serial
p = Serial()
# print CODE128 012ABCDabcd
p.barcode("{B012ABCDabcd", "CODE128", function_type="B")
Related