通过ESC/POS热敏打印机打印QR码? [英] printing QR codes through an ESC/POS thermal printer?

查看:296
本文介绍了通过ESC/POS热敏打印机打印QR码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在打印一些QR码(来自Ruby脚本),将ESC/POS命令写到Epson TM-T20热敏打印机.

I'm printing some QR codes (from a Ruby script) writing ESC/POS commands to a Epson TM-T20 thermal printer.

顺便说一句,我正在编写一个简单的ESC/POS命令打印机驱动程序". 我正在使用爱普生TM-T20(USB接口)的打印机 我正在使用Serialport gem从Windows 7主机进行一些测试.

BTW, I'm writing a simple ESC/POS commands printer "driver". The printer I'm using an Epson TM-T20 (USB interface) I'm doing some tests from a Windows 7 host, using serialport gem.

关于为打印格式的文本以及线性条形码编写ESC/POS命令很好,但是使用Epson提供的唯一可用文档(据我所知),我很难理解用于打印QR CODES的命令协议,请参阅: http://www.novopos.ch/client/EPSON/TM-T20/TM -T20_eng_qr.pdf

All fine about writing ESC/POS commands for print formatted texts and also linear barcodes, but I have problems uinderstanding the command protocol to print QR CODES, using the only available documentation supplyied by Epson (as far as I know), see: http://www.novopos.ch/client/EPSON/TM-T20/TM-T20_eng_qr.pdf

现在,关于QRCodes命令的部分对我来说是个晦涩的问题,我无法解释请求的字节序列.相反,我发现在这里找到的Nicolas示例非常有帮助: https://code.google.com/p/python-escpos/wiki/用法

Now, he section concerning QRCodes commands is for me pretty obscure and I was unable to interpreter requested byte sequences; instead I found very helpfull the Nicolas' example I found here: https://code.google.com/p/python-escpos/wiki/Usage

有了这个有用的字节码示例,我就能够成功打印QR码,请参见:
https://twitter.com/solyarisoftware/status/464740233008132096

Hacking that useful bytecodes example, I am able to successuffly print QR codes, see:
I https://twitter.com/solyarisoftware/status/464740233008132096

尽管如此,总的来说,我对ESC/POS消息格式感到困惑,特别是在我将一个长文本消息(> 400个字符)插入QR码的情况下……看来打印机拒绝了(不要这样做).打印)使用以下代码的包含超过400个字符的QR代码:

Nevertheless, in general, I'm confused on the ESC/POS message format, especially in case I would insert a long text message (> 400 chars) inside a QR code... It seem that printer reject (do not print) QR codes containing more than 400 chars using this code:

def test_qrcode (printer, text, print_also_text=false, qr_size=6.chr)

  s = text.size + 3
  lsb = (s % 256).chr
  msb = (s / 256).chr

  # https://code.google.com/p/python-escpos/wiki/Usage
  escpos = ""
  escpos << "\x1D\x28\x6B\x03\x00\x31\x43#{qr_size}"
  escpos << "\x1D\x28\x6B\x03\x00\x31\x45\x33"
  escpos << "\x1D\x28\x6B#{lsb}#{msb}\x31\x50\x30"
  escpos << text # 
  escpos << "\x1D\x28\x6B\x03\x00\x31\x51\x30"

  # writing byte streams directly to the serial port
  printer.write escpos

end

有人可以建议有关ESC/POS命令(=字节码序列)的CLEAR ESC/POS文档以打印QRCode(二维代码ESC/POS命令)吗?

Does someone can suggest a CLEAR ESC/POS DOCUMENTATION concerning the ESC/POS commands (=bytecodes sequences) to print QRCodes (two-dimensional code ESC/POS commands) ?

推荐答案

我为ESC/POS命令集找到的最完整的文档是: http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf

The most complete documentation I've found for the ESC/POS command set is this one: http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf

最近,我将QR码功能添加到POS客户端. 我发现打印此代码页437参考资料,特别是用于调试已打印的序列.

Recently, I added the QR code feature to a POS client. I've found it very useful to have a print out of this Code page 437 reference, especially for debugging a sequence that was printed.

我的示例在Java中,但您可以理解:

My example is in Java, but you can get the idea:

public void print_qr_code(String qrdata)
{
    int store_len = qrdata.length() + 3;
    byte store_pL = (byte) (store_len % 256);
    byte store_pH = (byte) (store_len / 256);


    // QR Code: Select the model
    //              Hex     1D      28      6B      04      00      31      41      n1(x32)     n2(x00) - size of model
    // set n1 [49 x31, model 1] [50 x32, model 2] [51 x33, micro qr code]
    // https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=140
    byte[] modelQR = {(byte)0x1d, (byte)0x28, (byte)0x6b, (byte)0x04, (byte)0x00, (byte)0x31, (byte)0x41, (byte)0x32, (byte)0x00};

    // QR Code: Set the size of module
    // Hex      1D      28      6B      03      00      31      43      n
    // n depends on the printer
    // https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=141
    byte[] sizeQR = {(byte)0x1d, (byte)0x28, (byte)0x6b, (byte)0x03, (byte)0x00, (byte)0x31, (byte)0x43, (byte)0x03};


    //          Hex     1D      28      6B      03      00      31      45      n
    // Set n for error correction [48 x30 -> 7%] [49 x31-> 15%] [50 x32 -> 25%] [51 x33 -> 30%]
    // https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=142
    byte[] errorQR = {(byte)0x1d, (byte)0x28, (byte)0x6b, (byte)0x03, (byte)0x00, (byte)0x31, (byte)0x45, (byte)0x31};


    // QR Code: Store the data in the symbol storage area
    // Hex      1D      28      6B      pL      pH      31      50      30      d1...dk
    // https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=143
    //                        1D          28          6B         pL          pH  cn(49->x31) fn(80->x50) m(48->x30) d1…dk
    byte[] storeQR = {(byte)0x1d, (byte)0x28, (byte)0x6b, store_pL, store_pH, (byte)0x31, (byte)0x50, (byte)0x30};


    // QR Code: Print the symbol data in the symbol storage area
    // Hex      1D      28      6B      03      00      31      51      m
    // https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=144
    byte[] printQR = {(byte)0x1d, (byte)0x28, (byte)0x6b, (byte)0x03, (byte)0x00, (byte)0x31, (byte)0x51, (byte)0x30};

    // flush() runs the print job and clears out the print buffer
    flush();

    // write() simply appends the data to the buffer
    write(modelQR);

    write(sizeQR);
    write(errorQR);
    write(storeQR);
    write(qrdata.getBytes());
    write(printQR);
    flush();
}

这篇关于通过ESC/POS热敏打印机打印QR码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆