简体   繁体   English

我如何使用 ESC POS 生成二维码?

[英]How i can generete qrcode with ESC POS?

I am developing QRCODE printing with the help of ESC / POS commands.我正在 ESC / POS 命令的帮助下开发 QRCODE 打印。 However, I can't generate a qrcode with more than 127 characters.但是,我无法生成超过 127 个字符的二维码。

Follows the code in C # :遵循 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;

in order to generate the qrcode string, I write the string to the file and have it printed.为了生成 qrcode 字符串,我将字符串写入文件并打印出来。

That's because it uses string variables.那是因为它使用字符串变量。

Even if you specify the encoding, it is not always possible to convert character data with a value of 0x80 or higher to the correct byte value.即使您指定了编码,也不总是可以将具有 0x80 或更高值的字符数据转换为正确的字节值。

If you use only a byte array, you can use long data.如果仅使用字节数组,则可以使用长数据。


Not all can be treated as text encoded in a single code page.并非所有的都可以被视为在单个代码页中编码的文本。

This is because commands that include control codes such as barcode printing are very likely to contain data that cannot be handled as character string text.这是因为包含控制代码(例如条形码打印)的命令很可能包含无法作为字符串文本处理的数据。

However, text and barcode printing can be mixed.但是,文本和条码打印可以混合使用。 Text data can be written to a file as encoded binary data (not a string).文本数据可以作为编码的二进制数据(不是字符串)写入文件。

If there is another program that reads data from the file and writes it to the printer, that program must open the file as a binary data file.如果有另一个程序从文件中读取数据并将其写入打印机,则该程序必须将文件作为二进制数据文件打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM