android - 热敏打印机打印条形码但打印字节而不是数字
问题描述
我尝试在热敏打印机中打印条码,但打印机打印的编号不同,我需要打印我定义的条码编号。
当前行为 我的号码是:“12345678” 条码打印机是:https : //snag.gy/VNxQs3.jpg 4950515253545556
预期行为 我的号码是:“12345678” 条码打印机是:https : //snag.gy/OVlebj.jpg 12345678
@Override
public void run()
{
try {
if(usbInterface != null && connection != null && mEndPoint != null) {
if(connection.claimInterface(usbInterface, true)) {
printBarcode(connection,usbInterface);
}
else {
System.out.println("ClaimInterface is false, print again.");
}
}
else {
System.out.println("Ocurrio un problema con la conexión...");
}
}
catch(Exception e) {
}
}
private void printBarcode(UsbDeviceConnection connection, UsbInterface interfaceUsb) {
String uuid = "12345678";
byte[] uuidBytes = uuid.getBytes();
byte[] formats = {(byte) 0x1d, (byte) 0x6b, (byte) 0x49, (byte)uuidBytes.length};
byte[] bytes = new byte[formats.length + uuidBytes.length];
System.arraycopy(formats, 0, bytes, 0, formats.length );
System.arraycopy(uuidBytes, 0, bytes, formats.length, uuidBytes.length);
connection.bulkTransfer(mEndPoint, bytes, bytes.length, TIMEOUT_COMMAND_PRINTER); }
在 Command POS 打印机的文档中,我发现: 1D 6B m d1…dk 00 Print bar code 或 1D 6B mn d1…dn 这与我使用的命令相同
在调试中,我可以看到打印机的数字与 uuidBytes.getBytes 相同,例如 [49,50,51,52,53,54,55,56] [ 1, 2, 3, 4, 5, 6, 7、8]
解决方案
推荐阅读
- python - 从列表中取消列出字典
- postgresql - 跨两列获取唯一值
- context-free-grammar - 给定的语言是有效的 CFG 吗?
- python - 如何更有效地找到两条线的交点?(在 Python 中嵌套 for 循环)
- oracle - Oracle PLSQL 数组不允许我索引或扩展
- ios - 如何在 iOS 文档选择器中选择 .pgw 文件?
- python - 如何解决 Python 和 Numpy 中的这种简单线性回归导致的错误?
- javascript - 仅使用某些道具映射数组
- android - 将字符串从 Android 应用程序传递到 Wear Os 应用程序
- javascript - Javascript不和谐机器人冷却不起作用