ESC/POS 二维码打印限制 124 个字符

问题描述 投票:0回答:1

我遇到了一个问题,涉及通过 ESC/POS 打印命令来打印超过 124 个字符的二维码。我在 Stack Overflow 上看过不同的帖子,但不明白这有什么问题。

具体来说,这个想法是在收据中打印二维码。数据被写入文本文件,然后由服务(rawbt)使用,该服务在热敏打印机(那些小打印机)中打印收据

我有一个代码可以正确打印二维码中的 124 个字符的数据,但不知道如何在同一个二维码中打印更多数据。额外的文字仅显示在二维码上方。

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 };

之后只需使用 BinaryWriter 将其写入文本文件即可。

我已经尝试过其他编码,例如 utf-8 和 iso-8859-1,但没有成功。

还对 store_pL 和 store_pH 进行了一些操作。 还做了一些测试,如果 qrdata.length > 124,则加 128,使 store_pL 更高,并将 store_pH 设置为 0。如果 store_pH 高于 0,则不会发生打印。

注意:这是一个 xamarin 应用程序。

请问有谁知道如何解决这个问题吗?

提前致谢!

qr-code escpos
1个回答
0
投票

我正在使用 Epson TM-m30II。我找到了解决这个问题的方法。这篇文章很好地描述了这个问题:

EPSON ESCPOS QRCode >380 个字符无法打印

在我的程序中,我使用 java.io.PrintWriter。这显然只支持 ASCII 字符集到 Dec(127) (https://en.wikipedia.org/wiki/ASCII)。

如果 QR 长度超过 124 + 3 个字符,则 store_pL 字节中发送的值不正确,并且打印机不知道传输数据的长度。

我通过不使用 java.io.PrintWriter 而是使用 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();
    
    }
}

© www.soinside.com 2019 - 2024. All rights reserved.