我在使用带有BT_MULTI连接类型的Zebra SDK中使用ConnectionBuilder类时遇到问题。 Zebra代表告诉我,这是一个已知的错误,他们没有修复ETA。
我用来连接打印机的代码如下:
if (isBluetoothAvailable()) {
// Make sure we still aren't connected to a printer
if (thePrinterConnection != null &&
thePrinterConnection.isConnected()) {
thePrinterConnection.close();
}
// Connect to the printer
Log.wtf(TAG, "Creating printer connection");
/* TODO: This should be how the printer is connected to check status when printing,
* TODO: but currently throws ConnectionException with "Invalid connection type".
*/
//thePrinterConnection = ConnectionBuilder.build("BT_MULTI:" + macAddress);
thePrinterConnection = ConnectionBuilder.build("BT:" + macAddress);
// Open the connection
Log.wtf(TAG, "Opening connection");
thePrinterConnection.open();
// Get instance of link os printer
thePrinterInstance = ZebraPrinterFactory.getLinkOsPrinter(thePrinterConnection);
return true;
} else {
return false;
}
注释掉的行是当前使用BT_MULTI标记的失败调用。
每次打印时,我都使用Connection类中的异步write()方法。要检查打印机是否已准备好进行下一次打印,请通过执行以下方法确保打印机已准备就绪:
public boolean isPrinterReady() {
/**
* FIXME: If the printer is receiving data while this is called,
* FIXME: it throws an exception, even if not printing. Above code might work with blocked
* FIXME: channel, but currently will not connect to printer.
*/
// Make sure we have a connection
if (thePrinterConnection != null && thePrinterInstance != null) {
try {
// Try to get current printer status
Log.wtf(TAG, "Printer is ready: " + thePrinterInstance.getCurrentStatus().isReadyToPrint);
return thePrinterInstance.getCurrentStatus().isReadyToPrint;
} catch (ConnectionException e) {
Log.wtf(TAG, "Error getting printer status", e);
return false;
}
} else {
Log.wtf(TAG, "Printer connection was null");
return false;
}
}
如上面的评论中所述,当打印机处于write()调用的中间并且我调用getCurrentStatus()方法时,它会锁定打印机。之后,它将不会返回状态(抛出格式错误的状态异常)并且不会继续打印。打印机需要重新启动才能再次运行。
有人有任何替代方案的建议吗?
谢谢!