【发布时间】:2021-02-21 12:07:22
【问题描述】:
我正在借助 ESC / POS 命令开发 QRCODE 打印。 但是,我无法生成超过 127 个字符的二维码。
遵循 C# 中的代码:
string ESC = Convert.ToString((char)27);
string GS = Convert.ToString((char)29);
string center = ESC + "a" + (char)1; //align center
string left = ESC + "a" + (char)0; //align left
string bold_on = ESC + "E" + (char)1; //turn on bold mode
string bold_off = ESC + "E" + (char)0; //turn off bold mode
string cut = ESC + "d" + (char)1 + GS + "V" + (char)66;
string initp = ESC + (char)64; //initialize printer
string buffer = ""; //store all the data that want to be printed
string QrData = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"; //data to be print in QR code
Encoding m_encoding = Encoding.GetEncoding("iso-8859-1"); //set encoding for QRCode
int store_len = (QrData).Length + 3;
byte store_pL = (byte)(store_len % 256);
byte store_pH = (byte)(store_len / 256);
buffer += initp; //initialize printer
buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 4, 0, 49, 65, 50, 0 });
buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 67, 8 });
buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 69, 48 });
buffer += m_encoding.GetString(new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 });
buffer += QrData;
buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 });
buffer += cut + initp;
为了生成二维码字符串,我将字符串写入文件并打印出来。
【问题讨论】:
标签: c# thermal-printer escpos