我正在尝试开发一个应用程序,让我可以用热敏打印打印门票。
我使用 bixolon 打印机,SRP-350III 型号,但每次我尝试连接它时,都会遇到相同的错误,这是堆栈跟踪:
2023-12-13 12:37:42.409 7762-7858 System.err com.gesplanet.gestion.TPVComercial W jpos.JposException: This device cannot be claimed for exclusive access.
2023-12-13 12:37:42.409 7762-7858 System.err com.gesplanet.gestion.TPVComercial W at com.bxl.services.posprinter.POSPrinterBaseService.claim(POSPrinterBaseService.java:158)
2023-12-13 12:37:42.409 7762-7858 System.err com.gesplanet.gestion.TPVComercial W at jpos.BaseJposControl.claim(BaseJposControl.java:284)
2023-12-13 12:37:42.409 7762-7858 System.err com.gesplanet.gestion.TPVComercial W at com.gesplanet.gestion.TPVComercial.Bixolon.BixolonPrinter.printerOpen(BixolonPrinter.java:187)
2023-12-13 12:37:42.409 7762-7858 System.err com.gesplanet.gestion.TPVComercial W at com.gesplanet.gestion.TPVComercial.PrinterConnectActivity
我正在遵循 bixolon 包含在 SDK 中的示例,但同样的情况正在发生。
有什么想法吗?
这是我用来连接的代码:
public boolean printerOpen(int portType, String logicalName, String address, boolean isAsyncMode) {
if (setTargetDevice(portType, logicalName, BXLConfigLoader.DEVICE_CATEGORY_POS_PRINTER, address)) {
int retry = 1;
if (portType == BXLConfigLoader.DEVICE_BUS_BLUETOOTH_LE) {
retry = 5;
}
//address = "/dev/bus/usb/001/004";
address = logicalName;
try {
for (JposEntry entry: bxlConfigLoader.getEntries()) {
bxlConfigLoader.removeEntry(entry.getLogicalName());
}
Log.i("BixolonPrinter 163", "Iniciando datos: \n LogicalName: "+logicalName+" \n " +
"DeviceCategory: " + BXLConfigLoader.DEVICE_CATEGORY_POS_PRINTER+" \n" +
"ProductName: " + BXLConfigLoader.PRODUCT_NAME_SRP_350III+" \n" +
"DeviceBus: " + portType+" \n" +
"Address: " + address);
bxlConfigLoader.addEntry(logicalName, BXLConfigLoader.DEVICE_CATEGORY_POS_PRINTER, BXLConfigLoader.PRODUCT_NAME_SRP_350III, portType, address);
bxlConfigLoader.saveFile();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
for (int i = 0; i < retry; i++) {
try {
posPrinter.open(logicalName);
posPrinter.claim(5000 * 2);
posPrinter.setDeviceEnabled(true);
posPrinter.setAsyncMode(isAsyncMode);
mPortType = portType;
mAddress = address;
return true;
} catch (JposException e) {
e.printStackTrace();
try {
posPrinter.close();
} catch (JposException e1) {
e1.printStackTrace();
}
}
}
}
return false;
}
这个问题你解决了吗?我对于 Android 12 及以上设备也有同样的问题。打印机型号 SPP-R410