LinkOS-Android-Samples icon indicating copy to clipboard operation
LinkOS-Android-Samples copied to clipboard

Zebra ZD410 bluetooth print issue from Android

Open kevincantstop opened this issue 6 years ago • 4 comments

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

kevincantstop avatar May 22 '19 08:05 kevincantstop

Have you found solution ? I'm facing the same problem.

syedalizaib avatar Jun 13 '19 11:06 syedalizaib

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

kevincantstop avatar Jun 15 '19 06:06 kevincantstop

Did anyone solved this issue without third party libraries?

mgolianek avatar Jul 23 '19 10:07 mgolianek

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.

fillobotto avatar Mar 16 '22 09:03 fillobotto