ESC-POS-.NET icon indicating copy to clipboard operation
ESC-POS-.NET copied to clipboard

QR Code Model 1 vs Model 2 Incorrect Printing

Open neon-dev opened this issue 5 years ago • 6 comments

I've noticed that QRCode Model 1 is not readable. And Model 2 looks to be Model 1 when visually comparing the printed code with a Model 1 code printed via this pre ESC-POS implementation:

String text = "test";

printerBuffer[0] = 0x1d;
printerBuffer[1] = 0x28;
printerBuffer[2] = 0x6b;
printerBuffer[3] = 4;
printerBuffer[4] = 0;
printerBuffer[5] = 0x31;
printerBuffer[6] = 0x41;
printerBuffer[7] = 0x49; // 0x49 - model 1 / 0x50 - model 2
printerBuffer[8] = 0x00;
serialPort.Write(printerBuffer, 0, 9);

printerBuffer[0] = 0x1d;
printerBuffer[1] = 0x28;
printerBuffer[2] = 0x6b;
printerBuffer[3] = 3;
printerBuffer[4] = 0;
printerBuffer[5] = 0x31;
printerBuffer[6] = 0x45;
printerBuffer[7] = 0x33; // 0x33 - Error correction level H (30% recovery capacity)
serialPort.Write(printerBuffer, 0, 8);

int len = 3 + text.Length;

printerBuffer[0] = 0x1d;
printerBuffer[1] = 0x28;
printerBuffer[2] = 0x6b;
printerBuffer[3] = (byte)(len % 256);
printerBuffer[4] = (byte)(len / 256);
printerBuffer[5] = 0x31;
printerBuffer[6] = 0x50;
printerBuffer[7] = 0x30;

char[] strChars = text.ToCharArray();
for (int i = 0; i < text.Length; i++) {
    printerBuffer[8 + i] = (byte)strChars[i];
}
serialPort.Write(printerBuffer, 0, 8 + text.Length);

printerBuffer[0] = 0x1d;
printerBuffer[1] = 0x28;
printerBuffer[2] = 0x6b;
printerBuffer[3] = 3;
printerBuffer[4] = 0;
printerBuffer[5] = 0x31;
printerBuffer[6] = 0x51;
printerBuffer[7] = 0x30;
serialPort.Write(printerBuffer, 0, 8);

This is the equivalent ESC-POS call:

printer.Write(E.Print2DCode(TwoDimensionCodeType.QRCODE_MODEL2, text, Size2DCode.SMALL, CorrectionLevel2DCode.PERCENT_30));

neon-dev avatar Aug 28 '20 09:08 neon-dev

Hello there, according to this enum QRCODE_MODEL2 should be cast as 50, but you are saying it results as 0x49 ?

image

Can you debug and provide the final byte array values returned by E.Print2DCode in your example? So we could compare byte by byte to your old code example?

igorocampos avatar Aug 28 '20 15:08 igorocampos

@igorocampos I think this enum (and possibly the others) is set wrong, if it should be hex 49 it needs to be specified as 0x49, not 49. 49 would be decimal 49 = hex 0x31. WHat do you think?

lukevp avatar Aug 28 '20 15:08 lukevp

@lukevp It is possible. I checked out the manual I had, and it is not clear if it means decimal or hexa. But look how the function number in the title uses decimal: fn=65 and not the hexa 0x41. So I assumed it was a pattern of the manual to describe all in Decimals, thus I made n1 enum assuming that.

image

But again, I'm not the one with the printer to test it out, if you say we should change, I'm happy to open the PR

igorocampos avatar Aug 28 '20 17:08 igorocampos

Don't trust this legacy code I posted too much. It was never used in production and I just inherited the project, so no guarantees for correctness. Now that you say it, to me it looks like the byte stream is incorrect and 0x49 should in fact be 49 / 0x31, since all other codes for commands I've seen were decimals.

I cannot test anything right now, so the only thing I can assure is that codes with QRCODE_MODEL1 failed to scan but QRCODE_MODEL2 can be scanned successfully. Whoever else has access to a printer should verify first.

neon-dev avatar Aug 28 '20 18:08 neon-dev

Please read some more about this in #79

igorocampos avatar Sep 30 '20 20:09 igorocampos

Hi, I finally had the chance to test a bit on a TM-T88IV printer. Using values 49, 0x49 and 0x50 resulted all in model 1 QR codes. Only 50 created a model 2 code, which I identified by the alignment pattern visible in the bottom right corner on size 4 (medium). So decimal values are correct. However I still could not ever read any of the printed model 1 codes. Maybe it's an issue with the scanner apps I tried. If anyone can tell me an app that is known to scan model 1 codes I'll gladly try and if it succeeds we can close this issue. Thanks

neon-dev avatar Apr 26 '21 16:04 neon-dev