万邦工业 MROer — 一站式工业用品网购平台

×
首页 > 服务与支持 > 通过Link-OS SDK开发,连接USB驱动时,反应时间超过30秒,如何解?

通过Link-OS SDK开发,连接USB驱动时,反应时间超过30秒,如何解?

问题现象

通过Link-OS SDK开发,使用USB驱动连接时,反应时间超过30秒。

原因分析

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) { }
    }
}
« 返回列表