Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zebra ZD410 bluetooth print issue from Android #3

Open
kevincantstop opened this issue May 22, 2019 · 4 comments
Open

Zebra ZD410 bluetooth print issue from Android #3

kevincantstop opened this issue May 22, 2019 · 4 comments

Comments

@kevincantstop
Copy link

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

@syedalizaib
Copy link

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

@kevincantstop
Copy link
Author

kevincantstop commented Jun 15, 2019

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

@mgolianek
Copy link

Did anyone solved this issue without third party libraries?

@fillobotto
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants