Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print QR code on zebra printer from android

i have Zebra MZ 220 printer, and i need to print the QR code from my android app via bluetooth. I am able to print text and images but not QR code.

I found this: https://km.zebra.com/kb/index?page=content&id=SO7133&actp=LIST_POPULAR

So, here's my code:

new Thread(new Runnable() {
public void run() {
    try {

        // Instantiate connection for given Bluetooth® MAC Address.
        ZebraPrinterConnection thePrinterConn = new BluetoothPrinterConnection("XX:XX:XX:XX:XX:XX");

        // Initialize 
        Looper.prepare();

        // Open the connection - physical connection is established here.
        thePrinterConn.open();



        // SO THIS SHOULD PRINT THE QR CODE BUT DOESN'T :(
        thePrinterConn.write("! 0 200 200 500 1\r\nB QR 10 100 M 2 U 10\r\nMA,QR code ABC123\r\nENDQR\r\nFORM\r\nPRINT".getBytes());



        //Make sure the data got to the printer before closing the connection
        Thread.sleep(500);

        // Close the connection to release resources.
        thePrinterConn.close();

        Looper.myLooper().quit();

    } catch (Exception e) {
        // Handle communications error here
        e.printStackTrace();
    }
}
}).start();

it dosen't work. So .... any help is appreciated :)

like image 937
Draško Avatar asked Apr 26 '13 09:04

Draško


1 Answers

You appear to have been very, very close. In CPCL (the RW's native language), all commands must end with both a new line and carriage return character. In your code, this correlates to an "\r\n" after each and every CPCL command. It looks like you forgot to put an "\r\n" after your final PRINT command in your CPCL chain.

Hopefully this information helps in the future instead of switching over to another framework. Using the Zebra SDK to send pure CPCL commands to the printer would have a significantly smaller bandwidth and should print faster than generating the QR barcode bitmap and sending the whole thing over. It may even print at a higher quality (and therefore be easier to scan) when using the native CPCL. And you wouldn't have to bundle another JAR in your app.

Reference: CPCL manual (section 2 page 1 note): http://www.zebra.com/content/dam/zebra/manuals/en-us/printer/cpcl-pm-en.pdf

like image 176
jason.zissman Avatar answered Sep 19 '22 12:09

jason.zissman