Generate QRCode and Print in Printer Thermal using ESC POS – ZIJIANG 58mm – Delphi 10.2

  

I’m trying to print qr code, on a thermal pos bluetooth printer in delphi, android platform (firemonkey).
the printer is connected, I can print the text, but I can’t generate and print the qr code, I would be grateful if someone can help.
The mark of the pos printer is P08-580LD (ZIJIANG).
this is the code i use in delphi-android 10.2 .
sock.connect;
// Reset Printer
ostream.write(StringToJA(escResetPrinter,’iso8859-2′));

ostream.write(StringToJA(pO8escBoldOn,’iso8859-2′));
ostream.write(StringToJA(‘Naziv 1’+escNewLine , ‘iso8859-2′));
ostream.write(StringToJA(pO8escBoldOff,’iso8859-2′));

ostream.write(StringToJA(pO8escFontA,’iso8859-2’));
ostream.write(StringToJA(‘Adresa’+escNewLine , ‘iso8859-2′));
ostream.write(StringToJA(escResetPrinter,’iso8859-2′));

ostream.write(StringToJA(pO8escFontB,’iso8859-2’));
ostream.write(StringToJA(‘MB xxxxx, ID HR-AB-99-0125–54’+escNewLine , ‘iso8859-2′));
ostream.write(StringToJA(escResetPrinter,’iso8859-2′));

ostream.write(StringToJA(pO8escUnerlineOn,’iso8859-2’));
ostream.write(StringToJA(‘IBAN: xxxxxxxxx’+escNewLine , ‘iso8859-2′));
ostream.write(StringToJA(pO8escUnerlineOff,’iso8859-2’));

ostream.write(StringToJA(‘OIB 99999999’+escNewLine , ‘iso8859-2′));

// start – qr-code //
ostream.write(StringToJA(chr(27)+chr(90)+chr(0)+chr(7)+chr(15)+chr(25)+chr(30)+’dada’ ,’iso8859-2′));

ostream.write(StringToJA(escResetPrinter,’iso8859-2′));

Sleep(250);
ostream.flush();
ostream.close;

This is documentation from the printer, and it says how to build the code, (decimal).
https://mega.nz/file/fu4zTCSR#UZ53LSty7dUpRyqzvz8li27amG1KvVlLk0slQFhd5Os
I managed to generate the qr code as below in the picture but it is not ok.

This is how the qr code should be generated according to the printer documentation

I found a function in android studio, how to build qr code, I would be grateful if someone knows how to turn a function into delphi.
…..
byte[] qrcode = PrinterCommand.getBarCommand("Zijiang Electronic Thermal Receipt Printer!", 0, 3, 6);//
Command.ESC_Align[2] = 0x01;
SendDataByte(Command.ESC_Align);
SendDataByte(qrcode);

public static byte[] getBarCommand(String str, int nVersion, int nErrorCorrectionLevel, int nMagnification)

{
if(nVersion<0 | nVersion >19 | nErrorCorrectionLevel<0 | nErrorCorrectionLevel > 3
| nMagnification < 1 | nMagnification > 8){
return null;
}

byte[] bCodeData = null;
try
{
bCodeData = str.getBytes("GBK");

}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
return null;
}

byte[] command = new byte[bCodeData.length + 7];
command[0] = 27;
command[1] = 90;
command[2] = ((byte)nVersion);
command[3] = ((byte)nErrorCorrectionLevel);
command[4] = ((byte)nMagnification);
command[5] = (byte)(bCodeData.length & 0xff);
command[6] = (byte)((bCodeData.length & 0xff00) >> 8);
System.arraycopy(bCodeData, 0, command, 7, bCodeData.length);
return command;
}

Comments are closed.