【发布时间】:2019-03-05 08:23:09
【问题描述】:
我正在开发中文蓝牙热敏打印机Model:SCAN-X,问题是长字符串的条形码无法扫描:
-
0123456789-- 打印和扫描 -
abcdefghijklmno-- 打印且不可扫描 -
INV-1-48-- 打印和扫描 -
INW-0001-0000000047--- 已打印且不可扫描 -
INW-001-0123456789--- 打印和扫描 -
INW-0001-123456789--- 已打印且不可扫描
我有点困惑我的代码有问题吗?
private void printBarcodeTest() {
OutputStream out = null;
try {
if ((socket == null) || (!socket.isConnected())) {
socket = BluetoothUtil.getSocket(mBluetoothPrinterDevice);
}
out = socket.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
// String barcodeContent1 = "INW-1-47"; // this is printing fine
String barcodeContent1 = "INW-0001-0000000047"; // this is printing, but not readable by barcode scanner
byte[] format = new byte[]{
0x1D, // GS
0x6B, // k
(byte) 73, // m (2) this is CODE_128
(byte) barcodeContent1.length() // n (number of barcode data bytes)
};
byte[] data = ESCUtil.byteMerger(new byte[][]{
format,
barcodeContent1.getBytes(StandardCharsets.UTF_8) //d1...dn
});
if (out != null) {
// init printer
// ESC , @
writeOutStream(out, new byte[]{0x1B, 0x40});
// // left margin
// // GS , L , nL , nH
// writeOutStream(out,new byte[]{ 0x1D , 0x4C ,(byte) (0 % 256),(byte) (0 / 256)});
// set alignment to center
// ESC ,a , n
writeOutStream(out, new byte[]{0x1B, 0x61, (byte) 1});
// set HRI position
// GS , ! , n
writeOutStream(out, new byte[]{0x1D, 0x48, (byte) 2});
// set height
// GS , h , n
writeOutStream(out, new byte[]{0x1D, 0x68, (byte) 2});
// set width
// GS , w , n
writeOutStream(out, new byte[]{0x1D, 0x77, (byte) 16);
// set data to print
writeOutStream(out, data);
// set next line feed
// LF
writeOutStream(out, new byte[]{0x0A});
// print n dots in feed
// ESC , J , n
writeOutStream(out, new byte[]{0x1B, 0x4A, (byte) 160});
}
try {
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
输出:
谁能帮帮我看看?
【问题讨论】:
-
如果我能看到扫描的图片,那可能会有所帮助。有时两边没有足够的安静区域,有时会出现边界框问题。
-
附上一张图片@BrianAnderson
标签: android thermal-printer barcode-printing escpos