'How to print QR code (or bitmap) to thermal printer?

I'm working with software that runs on linux/windows and also android.
On linux and windows, it prints QR codes by generating a bitmap and sending via ESC * to serial thermal printers.
On android it uses bluetooth, but for a particular device (a tablet with android 4.4) the printer is actually serial. So, it should work just the same as on linux or windows.

Only it doesn't, it prints this mess: misformed QR code

The printer self-test prints a QR code, so i assume it does support QR codes. I have no idea which make/model it is, searching for "80-IV-UR Thermal Printer" yields not much.

So i went ahead and tried implementing GS ( k instead. This is where i'm at:
GS ( k 165: 0x1D 0x28 0x6B 0x04 0x00 0x31 0x41 0x32 0x00 (n1 0x31, model 1)
GS ( k 167: 0x1D 0x28 0x6B 0x03 0x00 0x31 0x43 0x08 (n 0x08)
GS ( k 169: 0x1D 0x28 0x6B 0x03 0x00 0x31 0x45 0x31 (n 0x31, ECC M)
GS ( k 180: 0x1D 0x28 0x6B 0x0E 0x00 0x31 0x50 0x30 0x69 0x20 0x61 0x6D 0x20 0x61 0x20 0x74 0x65 0x73 0x74 (pL 14 pH 0 "i am a test")
GS ( k 181: 0x1D 0x28 0x6B 0x03 0x00 0x31 0x51 0x30 (m 0x30)
GS ( k 182: 0x1D 0x28 0x6B 0x03 0x00 0x31 0x52 0x30 (m 0x30)

However, when the printer reaches this part of the receipt, it just stops.
print 1: prints everything until before the QR
print 2: prints nothing
print 3: prints everything until before the QR
print 4: prints nothing
...

Am i using these commands wrong or there's something wrong elsewhere?
Is GS ( k 182 (transmit size) optional?
Are these ESC/POS commands widely supported? Since when?
Is the data part of GS ( k 180 in bytes/hexadecimal as well or should it be ASCII?



Solution 1:[1]

Turns out there's nothing wrong with my ESC/POS codes. After tracing around and finding the point where the software prints, i ran my own test and sent it to the serial port, producing a QR code.
Here's what i used for reference:

uint8_t myEscTst[] = { 0x1B, 0x40, 0x1B, 0x21, 0x00, 'H', 'e', 'l', 'l', 'o', ',', ' ', 't', 'h', 'e', 'r', 'm', 'a', 'l', ' ', 'w', 'o', 'r', 'l', 'd', '!', 0x1B, 0x64, 0x03 };
write(serialFD, myEscTst, sizeof(myEscTst));

uint8_t qrEsc165[] = { 0x1D, 0x28, 0x6B, 0x04, 0x00, 0x31, 0x41, 0x32, 0x00 }; 
write(serialFD, qrEsc165, sizeof(qrEsc165));

uint8_t qrEsc167[] = { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x43, 0x08 }; 
write(serialFD, qrEsc167, sizeof(qrEsc167));

uint8_t qrEsc169[] = { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x45, 0x31 }; 
write(serialFD, qrEsc169, sizeof(qrEsc169));

uint8_t qrEsc180[] = { 0x1D, 0x28, 0x6B, 0x0E, 0x00, 0x31, 0x50, 0x30, 'i', ' ', 'a', 'm', ' ', 'a', ' ', 't', 'e', 's', 't' }; 
write(serialFD, qrEsc180, sizeof(qrEsc180));

uint8_t qrEsc181[] = { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x51, 0x30 }; 
write(serialFD, qrEsc181, sizeof(qrEsc181));

uint8_t qrEsc182[] = { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x52, 0x30 }; 
write(serialFD, qrEsc182, sizeof(qrEsc182));

uint8_t qrEscLn3[] = { 0x1B, 0x64, 0x03 }; 
write(serialFD, qrEscLn3, sizeof(qrEscLn3));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vesperto