Printing QR in Epson TM-P20 (Java)

85 Views Asked by At

I'm trying to print some QR Code and there is no way to do this. Before the QR I successfully print some lines, so the printer works fine.

The printer is Epson TM-P20 and here is the manual: https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=140

Here's an example: https://www.b4x.com/android/forum/threads/impresion-qr-code-bluetooth-esc-pos-printer-class.122771/

I checked several times the sequences and did not see any mistake. The connection variable is the connection to the printer. I need you help! Thanks.

    String QR = "HELLO WORLD";

connection.write(Lines.getBytes("ISO-8859-15")); //WORKS FINE!

if (!QR.isEmpty())
{ 
    byte[] barcodeType = { 0x1d, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x31, 0x00}; //QR-CODE
    connection.write(barcodeType);
                
    connection.write(StringUtils.repeat(" ", 7).getBytes("ISO-8859-15"));
                
    byte[] sizeOfModule = { 0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x03}; 
    connection.write(sizeOfModule);
                
    byte[] errorCorrectionLevel = { 0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x30}; 
    connection.write(errorCorrectionLevel);
                
    byte[] qrDataBytes = QR.getBytes("ISO-8859-15");
                
    int len = QR.length() + 3;
    byte pH = (byte)(len / 256);
    byte pL = (byte)(len - (256 * pH));
                
    byte[] qrSymbolStorageArea = { 0x1d, 0x28, 0x6b, pL, pH, 0x31, 0x50, 0x30};             
    connection.write(concatenateByteArrays(qrSymbolStorageArea, qrDataBytes));
                
    byte[] qrPrint = { 0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30}; 
    connection.write(qrPrint);
                
    byte[] qrSizeInfo = { 0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x52, 0x30}; 
    connection.write(qrSizeInfo);                               
}





    private byte[] concatenateByteArrays(byte[] a, byte[] b)
    {
        byte[] result = new byte[a.length + b.length]; 
        System.arraycopy(a, 0, result, 0, a.length); 
        System.arraycopy(b, 0, result, a.length, b.length); 
        return result;
    }
0

There are 0 best solutions below