Moc*_*yat 8 printing android thermal-printer
我能够打印文本,但是当涉及条形码时,它始终不显示或仅显示数字参数
这是我的源代码
//barcode 128
byte[] formats = {(byte) 0x1d, (byte) 0x6b, (byte) 0x73,(byte) 0x0d};
byte[] contents = content.getBytes();
byte[] bytes = new byte[formats.length + contents.length];
System.arraycopy(formats, 0, bytes, 0, formats.length );
System.arraycopy(contents, 0, bytes, formats.length, contents.length);
usbCtrl.sendByte(bytes, dev);
usbCtrl.sendByte(LineFeed(), dev);
Run Code Online (Sandbox Code Playgroud)
但结果条形码没有显示,我错过了什么
请帮我
编辑
我找到了ESC/POS代码:
GS km d1 ... dk NUL或GS kmn d1 ... dk
但仍然没有工作
该GS kPOS代码有两个版本(因为你已经发现的):
GS k - print one dimensional barcode
m - barcode mode selector
[d]k - data bytes
NUL - terminator
Run Code Online (Sandbox Code Playgroud)
此版本仅适用于纯 ASCII 数据,因为它使用0x00(NUL) 作为终止符。
GS k - print one dimensional barcode
m - barcode mode selector
n - content length in bytes
[d]k - data bytes
Run Code Online (Sandbox Code Playgroud)
此版本使用额外的长度字节n来指示数据部分(它也仅适用于某些编码,包括CODE128)。
您的代码0x0d在命令字节中有杂散,也可能使用了错误的格式。
如果您打算打印纯 ASCII 数据格式,请执行如下命令:
byte[] formats = {(byte) 0x1d, (byte) 0x6b, (byte) 0x49};
byte[] contents = content.getBytes();
byte[] bytes = new byte[formats.length + contents.length + 1];
System.arraycopy(formats, 0, bytes, 0, formats.length );
System.arraycopy(contents, 0, bytes, formats.length, contents.length);
// add a terminating NULL
bytes[formats.length + contents.length] = (byte) 0x00;
Run Code Online (Sandbox Code Playgroud)
或者更安全的版本,因为它也有预期的数据长度:
byte[] contents = content.getBytes();
// include the content length after the mode selector (0x49)
byte[] formats = {(byte) 0x1d, (byte) 0x6b, (byte) 0x49, (byte)content.length};
byte[] bytes = new byte[formats.length + contents.length];
System.arraycopy(formats, 0, bytes, 0, formats.length );
System.arraycopy(contents, 0, bytes, formats.length, contents.length);
Run Code Online (Sandbox Code Playgroud)
如果两者都不起作用,那么您的打印机可能根本不支持CODE128.
5890是一种常见的足够规范和有大量廉价的“插入式”在市场上的替代品,其离开了更复杂的条形码实现,并且只包括简单值编码一样EAN8,EAN13等等。