EPSON ESC POS QR Code >380 字符不打印
EPSON ESCPOS QRCode >380 characters not print
我无法在二维码中打印超过 380 个字符。
C#中的代码如下:
protected ASCIIEncoding m_encoding = new ASCIIEncoding();
string QRdata = @"35150909165024000175590000193130072726117830|20150924062259|50.00||hdMEPiER6rjZKyKA+4+voi1nncxsAGFbYsEEqnh04SbvUEI/haUF4GUBPxT6Q2Uhf9f8QYgxiwxWo3GxRrvj4WnNeTYgAqUAYmOANPItNkOw0CppmZ4R8i1ZOlnftVhksCM0zrl4RiKgoazbN44hUu2nQf0W/JLvFXzXu12JlcSThNtmyJ6m9WBsMc/sf9BE14HDoXMyKRIQYt5TkEjilHH9Ffa0saRyUIp+Fji89/Moq8YCCFC+qC44XGxsvNCeeHUNOc1LgPP0DbU1miwpVnrBlEl87RU8Iy0r8fN/fNhbcStkwfTEvhYvZz42nEKHrmGTpGZYkHuTFCNZPq7aCA==";
int store_len = QRdata.Length + 3;
byte store_pL = (byte)(store_len % 256);
byte store_pH = (byte)(store_len / 256);
string txt = m_encoding.GetString(new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }); //FUNCTION 180
txt += QRdata;
txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 69, 48 });//FUNCTION 169
txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 67, 5 });//FUNCTION 167
txt += m_encoding.GetString(new byte[] { 29, 40, 107, 4, 0, 49, 65, 50, 0 });//FUNCTION 165
txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 });//FUNCTION 181
尝试打印时出现如下:
ASCII 是一个问题,因为它是 7 位编码,但 store_PL
值大于 127(占用 8 位)。以下是正在发生的事情的演示:
ASCIIEncoding m_encoding = new ASCIIEncoding();
string QRdata = @"35150909165024000175590000193130072726117830|20150924062259|50.00||hdMEPiER6rjZKyKA+4+voi1nncxsAGFbYsEEqnh04SbvUEI/haUF4GUBPxT6Q2Uhf9f8QYgxiwxWo3GxRrvj4WnNeTYgAqUAYmOANPItNkOw0CppmZ4R8i1ZOlnftVhksCM0zrl4RiKgoazbN44hUu2nQf0W/JLvFXzXu12JlcSThNtmyJ6m9WBsMc/sf9BE14HDoXMyKRIQYt5TkEjilHH9Ffa0saRyUIp+Fji89/Moq8YCCFC+qC44XGxsvNCeeHUNOc1LgPP0DbU1miwpVnrBlEl87RU8Iy0r8fN/fNhbcStkwfTEvhYvZz42nEKHrmGTpGZYkHuTFCNZPq7aCA==";
int store_len = QRdata.Length + 3; // 414
byte store_pL = (byte)(store_len % 256); // 158
byte store_pH = (byte)(store_len / 256); // 1
byte[] data = new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }; //FUNCTION 180
string txt = m_encoding.GetString(data);
byte[] invalidData = m_encoding.GetBytes(txt);
数据原值(预期一个):
1d 28 6b 9e 01 31 50 30
串口实际接收到的数据(由于158
值无法编码为7位ASCII):
1d 28 6b 3f 01 31 50 30
如您所见,值 158 (0x9e)
更改为 63 (0x3f)
,因为未知符号被编码为 ?
。
那么,这个问题有2个解决方案。一种是使用Encoding m_encoding = Encoding.GetEncoding("iso-8859-1");
编码,或者任何其他扩展的ASCII编码,但它应该在您的代码中使用的字节编码和串口设置之间保持同步。而另一种解决方案是完全不使用字符串,而是使用字节数组。
我无法在二维码中打印超过 380 个字符。
C#中的代码如下:
protected ASCIIEncoding m_encoding = new ASCIIEncoding();
string QRdata = @"35150909165024000175590000193130072726117830|20150924062259|50.00||hdMEPiER6rjZKyKA+4+voi1nncxsAGFbYsEEqnh04SbvUEI/haUF4GUBPxT6Q2Uhf9f8QYgxiwxWo3GxRrvj4WnNeTYgAqUAYmOANPItNkOw0CppmZ4R8i1ZOlnftVhksCM0zrl4RiKgoazbN44hUu2nQf0W/JLvFXzXu12JlcSThNtmyJ6m9WBsMc/sf9BE14HDoXMyKRIQYt5TkEjilHH9Ffa0saRyUIp+Fji89/Moq8YCCFC+qC44XGxsvNCeeHUNOc1LgPP0DbU1miwpVnrBlEl87RU8Iy0r8fN/fNhbcStkwfTEvhYvZz42nEKHrmGTpGZYkHuTFCNZPq7aCA==";
int store_len = QRdata.Length + 3;
byte store_pL = (byte)(store_len % 256);
byte store_pH = (byte)(store_len / 256);
string txt = m_encoding.GetString(new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }); //FUNCTION 180
txt += QRdata;
txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 69, 48 });//FUNCTION 169
txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 67, 5 });//FUNCTION 167
txt += m_encoding.GetString(new byte[] { 29, 40, 107, 4, 0, 49, 65, 50, 0 });//FUNCTION 165
txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 });//FUNCTION 181
尝试打印时出现如下:
ASCII 是一个问题,因为它是 7 位编码,但 store_PL
值大于 127(占用 8 位)。以下是正在发生的事情的演示:
ASCIIEncoding m_encoding = new ASCIIEncoding();
string QRdata = @"35150909165024000175590000193130072726117830|20150924062259|50.00||hdMEPiER6rjZKyKA+4+voi1nncxsAGFbYsEEqnh04SbvUEI/haUF4GUBPxT6Q2Uhf9f8QYgxiwxWo3GxRrvj4WnNeTYgAqUAYmOANPItNkOw0CppmZ4R8i1ZOlnftVhksCM0zrl4RiKgoazbN44hUu2nQf0W/JLvFXzXu12JlcSThNtmyJ6m9WBsMc/sf9BE14HDoXMyKRIQYt5TkEjilHH9Ffa0saRyUIp+Fji89/Moq8YCCFC+qC44XGxsvNCeeHUNOc1LgPP0DbU1miwpVnrBlEl87RU8Iy0r8fN/fNhbcStkwfTEvhYvZz42nEKHrmGTpGZYkHuTFCNZPq7aCA==";
int store_len = QRdata.Length + 3; // 414
byte store_pL = (byte)(store_len % 256); // 158
byte store_pH = (byte)(store_len / 256); // 1
byte[] data = new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }; //FUNCTION 180
string txt = m_encoding.GetString(data);
byte[] invalidData = m_encoding.GetBytes(txt);
数据原值(预期一个):
1d 28 6b 9e 01 31 50 30
串口实际接收到的数据(由于158
值无法编码为7位ASCII):
1d 28 6b 3f 01 31 50 30
如您所见,值 158 (0x9e)
更改为 63 (0x3f)
,因为未知符号被编码为 ?
。
那么,这个问题有2个解决方案。一种是使用Encoding m_encoding = Encoding.GetEncoding("iso-8859-1");
编码,或者任何其他扩展的ASCII编码,但它应该在您的代码中使用的字节编码和串口设置之间保持同步。而另一种解决方案是完全不使用字符串,而是使用字节数组。