I am developing an Android app which prints to a Zebra ZQ520 printer, over a Bluetooth connection, using the ZSDK API. I would like to be able test if the connection to the printer is active or if I need to reconnect (eg when the printer has gone to sleep). I have tried using the printer.getCurrentStatus() method, with the intention of then using the isReadyToPrint flag, but I am consistently getting a ZebraPrinterConnectionException ("Malformed status response - unable to determine printer status"). Is there any other way to check the printer/connection status?
Test printer status in Android// Expert user has replied. |
3 Replies
Thanks Manuel. I downloaded the latest version of the SDK and actually found the answer in the included demo app. For the ZQ520, I needed to get the status using ZebraPrinterLinkOs.
Full code:
ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.createLinkOsPrinter(printer);
PrinterStatus printerStatus = (linkOsPrinter != null) ? linkOsPrinter.getCurrentStatus() : printer.getCurrentStatus();
Hi Stephen,
Please, follow the example below. It should work fine to check the status of the printer before to send a print job.
Also, you can go to the link below to get more information about Zebra's API.
Zebra API for Android (build v2.9.2275)
package test.zebra.sdk.printer.examples;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.comm.BluetoothConnection;
import com.zebra.sdk.printer.PrinterStatus;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
public class PrinterStatusExample {
public static void main(String[] args) throws Exception {
Connection connection = new BluetoothConnection(theBTMacAddress);
try {
connection.open();
ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
PrinterStatus printerStatus = printer.getCurrentStatus();
if (printerStatus.isReadyToPrint) {
System.out.println("Ready To Print");
} else if (printerStatus.isPaused) {
System.out.println("Cannot Print because the printer is paused.");
} else if (printerStatus.isHeadOpen) {
System.out.println("Cannot Print because the printer head is open.");
} else if (printerStatus.isPaperOut) {
System.out.println("Cannot Print because the paper is out.");
} else {
System.out.println("Cannot Print.");
}
} catch (ConnectionException e) {
e.printStackTrace();
} catch (ZebraPrinterLanguageUnknownException e) {
e.printStackTrace();
} finally {
connection.close();
}
}
}
Another situation that could be happening is related to the Printer language:
The ZQ510 printer normally is by default in Line_Print.
For more information about it, I would recommend to review this article.
Zebra Technologies - Best Practices in Creating a Printing Application for Zebra Printers
We recommend to set up the language to ZPL.
Please, try this line before to get status
SGD.SET("device.languages", "hybrid_xml_zpl", connection);
or
SGD.SET("device.languages", "zpl", connection);
Please, let me know if you need more assistance.
Thanks,
MC