設為首頁收藏本站

艾歐踢論壇

 找回密碼
 立即註冊

QQ登錄

只需一步,快速開始

搜索
熱搜: 活動 交友 discuz
查看: 1593|回復: 0
打印 上一主題 下一主題

printing QR codes through an ESC/POS thermal printer

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2016-6-26 22:26:39 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. ef test_qrcode (printer, text, print_also_text=false, qr_size=6.chr)

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

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

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

  14. end
複製代碼
in general, 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:****example is in Java
  1. public void print_qr_code(String qrdata)
  2. {
  3.     int store_len = qrdata.length() + 3;
  4.     byte store_pL = (byte) (store_len % 256);
  5.     byte store_pH = (byte) (store_len / 256);


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

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


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


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


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

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

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

  33.     write(sizeQR);
  34.     write(errorQR);
  35.     write(storeQR);
  36.     write(qrdata.getBytes());
  37.     write(printQR);
  38.     flush();
  39. }
複製代碼



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 轉播轉播 分享分享 分享淘帖
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|Archiver|手機版|艾歐踢創新工坊    

GMT+8, 2024-5-17 07:51 , Processed in 0.208919 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表