I'm working on Chinese Bluetooth thermal printer Model:SCAN-X
, Problem is barcodes for long strings are not scannable:
0123456789
-- printed & scannableabcdefghijklmno
-- printed & not scannableINV-1-48
-- printed & scannableINW-0001-0000000047
--- printed & not scannableINW-001-0123456789
--- printed & scannableINW-0001-123456789
--- printed & not scannable
Here is specified guide in ESC/POS doc of printer
I am bit confused is there something wrong with my code?
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();
}
}
Output:
Can anyone please take a look and guide me?