LinkOS-Android-Samples
LinkOS-Android-Samples copied to clipboard
Zebra ZD410 bluetooth print issue from Android
Hi guys,
Currently I'm using model ZD410 for bluetooth print, it's paired up with my device successfully, but when I try to connect it pops out this error:
com.zebra.sdk.comm.ConnectionException: Could not connect to device: read failed, socket might closed or timeout, read ret: -1
Here is my code:
private byte[] getPrintCommand(int userPrintCount, String userText1, String userText2, String userText3) {
String cpclConfigLabel = "! 0 200 200 304 " + userPrintCount + "\r\n" + "TEXT 0 3 10 10 CYC LABEL START\r\n" + "TEXT 0 3 10 40 " + userText1 + " " + userText2 + " " + userText3 + "\r\n" + "BARCODE 128 1 1 40 10 80 " + userText1 + "\r\n" + "TEXT 0 3 10 150 CYC LABEL END\r\n" + "FORM\r\n" + "PRINT\r\n";
return cpclConfigLabel.getBytes();
}
public void onPrintButtonClicked(View view) {
EditText serial = findViewById(R.id.serial);
EditText label = findViewById(R.id.label);
Connection connection = new BluetoothConnection(serial.getText().toString());
try {
connection.open();
if (connection.isConnected()) {
ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
PrinterLanguage pl = printer.getPrinterControlLanguage();
connection.write(this.getPrintCommand(1, label.getText().toString(), "Hello World 2", "Hello World 3"));
}
} catch (ConnectionException ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
} catch (ZebraPrinterLanguageUnknownException ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
connection.close();
} catch (ConnectionException e) {
e.printStackTrace();
}
}
}
Is there something wrong with the printer or code?
Thanks
Have you found solution ? I'm facing the same problem.
Try BLE mode with Android native API. I found zebra SDK is buggy to connect to ZD410. It only works if I use native BLE android API
This library works very well for me. https://github.com/Jasonchenlijian/FastBle.
To debug zebra ZD410, you can try this app. https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner&hl=en_AU . It helps me a lot
Good luck
Did anyone solved this issue without third party libraries?
You actually don't have to use 3rd party libraries. Just use Zebra BTLE SDK for discovery and connection: https://techdocs.zebra.com/link-os/2-14/android_btle/ Then all the rest will work as usual.