Link-OS SDK中提供了一個DEMO,使用"ZebraPrinter printer = ZebraPrinterFactory.getInstance(printerConnection)"來從驅動中獲取連接,但該方法速度比較慢,目前提供了"com.zebra.sdk.comm.DriverPrinterConnection"來替代"ZebraPrinterFactory.getInstance"方法,例子如下:
private void sendAndWaitDate() {
Connection conn = null;
try {
conn = new DriverPrinterConnection("ZDesigner ZT410-300dpi ZPL");
conn.open();
byte[] zpl = "^XA^FN1^RFR,H,0,12,2^FS^FH_^HV1,256^FS^RFW,H,1,14,1^FD3000313233343536373839414243^FS^XZ".getBytes();
byte[] tid = null;
tid = conn.sendAndWaitForResponse(zpl, 500, 500, null);
DemoDialog.showErrorDialog(SendFileDemo.this, tid.toString(), tid.toString());
} catch (ConnectionException e) {
DemoDialog.showErrorDialog(SendFileDemo.this, e.getMessage(), "Connection Error!");
} finally {
try {
if (conn != null)
conn.close();
} catch (ConnectionException e) {
}
}
}