I'm having an issue, regarding printing commands through ESC/POS to print a QR code, with more than 124 chars. I have seen different posts on Stack Overflow, but can't understand what is wrong with this.
To contextualize, the idea, is to print a qrcode in a receipt. The data is written to a text file, and after that is used by a service (rawbt) which prints the receipt in a thermal printer (those small ones)
I have a code that prints until 124 chars of data in qrcode correctly, but can't figure out how to print more in the same QR. extra text just shows up above QR code.
string QrData = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 XX";
int store_len = (QrData).Length + 3;
byte store_pL = (byte)(store_len % 256);
byte store_pH = (byte)(store_len / 256);
byte[] b = new byte[] { 29, 40, 107, 4, 0, 49, 65, 50, 0 };
byte[] b1 = new byte[] { 29, 40, 107, 3, 0, 49, 67, 9 };
byte[] b2 = new byte[] { 29, 40, 107, 3, 0, 49, 69, 48 };
byte[] b3 = new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 };
byte[] bytes = Encoding.ASCII.GetBytes(QrData);
byte[] b4 = new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 };
after that just use BinaryWriter to write this to the text file.
I've already tried other encodings, like utf-8 and iso-8859-1, but no luck.
Also did some play with store_pL and store_pH. Did also some tests, when if the qrdata.length is > 124, adds up 128 to it, making the store_pL higher, and setting the store_pH to 0. If store_pH is higher than 0, no printing occurs.
note: this is a xamarin app.
Anyone knows please how to solve this?
Thanks in advance!
I am working with an Epson TM-m30II.
I found a solution for this problem. The problem is well described in this post:
EPSON ESCPOS QRCode >380 characters not print
In my program I worked with the java.io.PrintWriter. This apparently only supports the ASCII character set up to Dec(127) (https://en.wikipedia.org/wiki/ASCII).
If the QR is longer than 128 characters, an incorrect value is sent in the store_pL byte and the printer does not know the length of the transmitted data.
I solved the problem by not using the java.io.PrintWriter but the java.io.DataOutputStream.
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
public class EscPos {
public static void main(String[] args) throws IOException {
Socket sock = new Socket("192.168.10.45", 9100);
DataOutputStream outputStream = new DataOutputStream(sock.getOutputStream());
String qrCode = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 XX";
int store_len = qrCode.length() + 3;
byte store_pL = (byte) (store_len % 256);
byte store_pH = (byte) (store_len / 256);
outputStream.flush();
// https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=140 (165)
byte [] bSendFunktion165 = {(byte)0x1D, (byte)0x28, (byte)0x6B, (byte)0x04, (byte)0x00, (byte)0x31, (byte)0x41, (byte)0x32, (byte)0x00};
outputStream.write(bSendFunktion165);
//https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=141 (167)
byte [] bSendFunktion167 = {(byte)0x1D, (byte)0x28, (byte)0x6B, (byte)0x03, (byte)0x00, (byte)0x31, (byte)0x43, (byte)0x9};
outputStream.write(bSendFunktion167);
//https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=142 (169)
byte [] bSendFunktion169 = {(byte)0x1D, (byte)0x28, (byte)0x6B, (byte)0x03, (byte)0x00, (byte)0x31, (byte)0x45, (byte)0x30};
outputStream.write(bSendFunktion169);
//https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=143 (180)
byte [] bSendFunktion180 = {(byte)0x1D, (byte)0x28, (byte)0x6B, store_pL, store_pH, (byte)0x31, (byte)0x50, (byte)0x30};
outputStream.write(bSendFunktion180);
byte [] bSendQRCode = qrCode.getBytes();
outputStream.write(bSendQRCode);
//https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=143 (181)
byte [] bSendFunktion181 = {(byte)0x1D, (byte)0x28, (byte)0x6B, (byte)0x03, (byte)0x00, (byte)0x31, (byte)0x51, (byte)0x30};
outputStream.write(bSendFunktion181);
outputStream.flush();
outputStream.write((byte)0x0A);
outputStream.write((byte)0x0A);
outputStream.write((byte)0x0A);
outputStream.write((byte)0x0A);
byte [] bCut = {(byte)0x1D, (byte)0x56, (byte)0x30};
outputStream.write(bCut);
//------------------------------------------------------------------
outputStream.close();
sock.close();
}
}
I hope I could help you. Happy holidays
Steffi