I have downloaded the JAVA SDK and tried to pritn to a ZEBRA ZD620 using direct USB communication without driver
Printing labels is immediate while getting the printer status take about 10 seconds.
As you can see in the code I have used two ways to get the Host Status:
Connection.sendAndWaitForResponse("~Hs".getBytes(), 2000, 2000, "V");
and
ZebraPrinter.getCurrentStatus();
Any suggestion?
public static void usbDriverlessTest() throws ConnectionException {
System.out.println("Discovered USB printer list:\r\n");
DiscoveredUsbPrinter discoveredPrinter = null;
for (DiscoveredUsbPrinter printer : UsbDiscoverer.getZebraUsbPrinters(new ZebraPrinterFilter())) {
System.out.println(printer);
discoveredPrinter = printer;
}
System.out.println("End USB printer list\r\n");
Connection imz = ConnectionBuilder.build(discoveredPrinter.address);
try {
imz.open();
byte[] hi_return = null;
ZebraPrinter printer = ZebraPrinterFactory.getInstance(imz);
String label = "^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^PQ1,0,1,N^XZ";
// printer.sendCommand(label);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println(sdf.format(new Date()));
// https://live-zebratechnologies.devportal.apigee.io/thread/35973
PrinterStatus printerStatus = printer.getCurrentStatus();
System.out.println("printerStatus.labelLengthInDots=" + printerStatus.labelLengthInDots);
System.out.println("printerStatus.labelsRemainingInBatch=" + printerStatus.labelsRemainingInBatch);
System.out.println("printerStatus.numberOfFormatsInReceiveBuffer=" + printerStatus.numberOfFormatsInReceiveBuffer);
System.out.println("printerStatus.isReadyToPrint=" + printerStatus.isReadyToPrint);
System.out.println("printerStatus.isReceiveBufferFull=" + printerStatus.isReceiveBufferFull);
System.out.println(sdf.format(new Date()));
hi_return = imz.sendAndWaitForResponse("~Hs".getBytes(), 2000, 2000, "V");
System.out.println(new String(hi_return));
System.out.println(sdf.format(new Date()));
hi_return = imz.sendAndWaitForResponse("~HQES".getBytes(), 2000, 2000, "V");
System.out.println(new String(hi_return));
System.out.println(sdf.format(new Date()));
} catch (ZebraPrinterLanguageUnknownException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
imz.close();
}
}
1 Replies
Using the getCurrentStatus() is the correct way to obtain the printer status. Instead of using printer.getCurrentStatus(), I'd suggest to use either PrinterUtil.getCurrentStatus() or printerLinkOs.getCurrentStatus(). This way, you save about 5 seconds. See the code snippet below.
Alternatively, we can modify the MaxTimeoutForRead on the connection object. The default is 5 seconds. To shorten the value, we call the setMaxTimeoutForRead() on the connection object. For example, if we want to change the default 5 seconds to a half second, we do the following. So that we shorten the time of the return from getCurrentStatus() .