Android POS打印机ESC / POS

前端之家收集整理的这篇文章主要介绍了Android POS打印机ESC / POS前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

所以我一直在为蓝牙打印机编写一个Android应用程序,我已经意识到这实际上是ESC / POS标准:http://nicholas.piasecki.name/blog/wp-content/uploads/2009/12/ESC-POS-Command-Guide.pdf

现在我用于打印机的文档是这些命令的有限子集,可在此处找到:https://dl.dropboxusercontent.com/u/88265006/%E4%BA%A7%E5%93%81/Printer用户手册/ SP-MP-300-技术手册.pdf

  1. private void initPrinter() {
  2. byte[] init = new byte[2];
  3. init[0] = 0x1B;
  4. init[1] = 0x40;
  5. mService.write(init);
  6. }
  7. private void printText(String message){
  8. byte[] send;
  9. try{
  10. send = message.getBytes("UTF8");
  11. }
  12. catch(UnsupportedEncodingException e){
  13. send = "Error".getBytes();
  14. }
  15. initPrinter();
  16. mService.write(send);
  17. }

我可以连接到打印机,用“ESC @”命令初始化它,我可以用上面的命令编写,但我似乎无法获得任何条形码的任何“视觉”效果.这是我尝试使用1D EAN13代码(0000000000000):

  1. byte[] height = new byte[3];
  2. height[0] = 0x1D;
  3. height[1] = 0x68;
  4. height[2] = (byte)30;
  5. //height[3] = 0;
  6. byte[] width = new byte[3];
  7. width[0] = 0x1D;
  8. width[1] = 0x77;
  9. width[2] = (byte)3;
  10. byte[] textPos = new byte[3];
  11. textPos[0] = 0x1D;
  12. textPos[1] = 0x48;
  13. textPos[2] = (byte)2;
  14. byte[] level = new byte[3];
  15. level[0] = 0x1D;
  16. level[1] = 0x51;
  17. level[2] = (byte)32;
  18. byte[] code = new byte[18];
  19. code[0] = 0x1D;
  20. code[1] = 0x6B;
  21. code[2] = 0x02;
  22. code[3] = 0x0D;
  23. code[4] = 0x30;//1
  24. code[5] = 0x30;//2
  25. code[6] = 0x30;//3
  26. code[7] = 0x30;//4
  27. code[8] = 0x30;//5
  28. code[9] = 0x30;//6
  29. code[10] = 0x30;//7
  30. code[11] = 0x30;//8
  31. code[12] = 0x30;//9
  32. code[13] = 0x30;//10
  33. code[14] = 0x30;//11
  34. code[15] = 0x30;//12
  35. code[16] = 0x30;//13
  36. code[17] = 0x00;//end
  37. mService.write(height);
  38. mService.write(width);
  39. mService.write(textPos);
  40. mService.write(level);
  41. mService.write(code);

其中mService实际写入数据.我得到的最好输出是0█0█0,00,00100,如果连续多次发送数据.

如果我在多次发送后删除最后的结束字节,我得到14 0,我也尝试在高度,宽度,textPosition和级别数组中添加结尾0,没有任何影响.

我也看了以下几个地方:
http://www.manualslib.com/manual/689542/Axiohm-A795.html?page=91
http://pyramidacceptors.com/phoenix-printer/esc-pos-command-set/
http://www.vbforums.com/showthread.php?754493-RESOLVED-Printing-Barcode-with-ESC-POS-on-Epson-Printers
http://www.manualslib.com/manual/753647/Axiohm-A630.html?page=51
https://www.sparkfun.com/datasheets/Components/General/Driver%20board.pdf
Where can I find a “ESC/POS” Epson Barcode Test Program?

最佳答案
好吧事实证明,在ESC / POS中,打印机实际上为您计算了一些数据.我不应该把检查字节(实际条形码的最后一位数字)放在我发送到打印件的数据中.

当然,我的文档缺少所有< =符号并没有帮助.我最终使用此文档寻求帮助:http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf

我还在研究二维码打印,但我很确定我的问题有点类似.

猜你在找的Android相关文章