所以我一直在写一个蓝牙打印机一会儿一个Android应用程序,我已经意识到,这实际上是ESC/POS标准:http://nicholas.piasecki.name/blog/wp-content/uploads/2009/12/ESC-POS-Command-Guide.pdfAndroid的POS打印机ESC/POS
现在我使用的文档我的打印机是这些命令的一个有限的子集,并可以在这里找到:https://dl.dropboxusercontent.com/u/88265006/%E4%BA%A7%E5%93%81/Printer的%20user%20manual/SP-MP-300-技术%20Manual.pdf
private void initPrinter() {
byte[] init = new byte[2];
init[0] = 0x1B;
init[1] = 0x40;
mService.write(init);
}
private void printText(String message){
byte[] send;
try{
send = message.getBytes("UTF8");
}
catch(UnsupportedEncodingException e){
send = "Error".getBytes();
}
initPrinter();
mService.write(send);
}
我可以连接到打印机,初始化它带有一个“ESC @”命令,我可以用上面的命令编写,但我似乎无法获得任何类型的“视觉”效果的条形码。这是我尝试使用1D EAN13代码(0000000000000):
byte[] height = new byte[3];
height[0] = 0x1D;
height[1] = 0x68;
height[2] = (byte)30;
//height[3] = 0;
byte[] width = new byte[3];
width[0] = 0x1D;
width[1] = 0x77;
width[2] = (byte)3;
byte[] textPos = new byte[3];
textPos[0] = 0x1D;
textPos[1] = 0x48;
textPos[2] = (byte)2;
byte[] level = new byte[3];
level[0] = 0x1D;
level[1] = 0x51;
level[2] = (byte)32;
byte[] code = new byte[18];
code[0] = 0x1D;
code[1] = 0x6B;
code[2] = 0x02;
code[3] = 0x0D;
code[4] = 0x30;//1
code[5] = 0x30;//2
code[6] = 0x30;//3
code[7] = 0x30;//4
code[8] = 0x30;//5
code[9] = 0x30;//6
code[10] = 0x30;//7
code[11] = 0x30;//8
code[12] = 0x30;//9
code[13] = 0x30;//10
code[14] = 0x30;//11
code[15] = 0x30;//12
code[16] = 0x30;//13
code[17] = 0x00;//end
mService.write(height);
mService.write(width);
mService.write(textPos);
mService.write(level);
mService.write(code);
其中mService实际上写入数据。我获得的最佳输出是0█0█0█0█0█0█0█0█0█0█0█0█0█0█ - 连续多次发送数据后。
如果我在多次发送后删除最后的结束字节,我得到了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?
你确定你正在转换你的字节。 Java有一种怪异的十六进制到二进制转换(二进制转换)的方式。这可能是导致你的问题的原因。 – SeahawksRdaBest 2014-10-20 22:10:06
我最终创建了易于阅读的常量,例如私有静态字节GS = 0x1d;但Java的字节表示不是问题,但感谢您试图帮助:) – 2014-10-25 20:56:38