With it, I want to get the status of a printer, and it works when there isn't any error on the printer (so when the cover is closed, the paper isn't empty and the cutter is ready).
But when I test to run this code when I open the cover, of anything that make the status offline, I get a StarIOPortException ('printer is offline') instead of the status with the flag corresponding to the offline causes.
To resolve that, in the file 'cordova-plugin-starprnt/src/android/StarPRNT.java', I tried to edit the checkStatus method :
public void checkStatus(String portName, String portSettings, CallbackContext callbackContext) {
final Context context = this.cordova.getActivity();
final CallbackContext _callbackContext = callbackContext;
final String _portName = portName;
final String _portSettings = portSettings;
cordova.getThreadPool()
.execute(new Runnable() {
public void run() {
StarIOPort port = null;
try {
port = StarIOPort.getPort(_portName, _portSettings, 10000, context);
// A sleep is used to get time for the socket to completely open
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
StarPrinterStatus status;
Map<String, String> firmwareInformationMap = port.getFirmwareInformation();
status = port.retreiveStatus();
JSONObject json = new JSONObject();
try {
json.put("offline", status.offline);
json.put("coverOpen", status.coverOpen);
json.put("cutterError", status.cutterError);
json.put("receiptPaperEmpty", status.receiptPaperEmpty);
json.put("ModelName", firmwareInformationMap.get("ModelName"));
json.put("FirmwareVersion", firmwareInformationMap.get("FirmwareVersion"));
// TEST
//json.put("ModelName", "model");
//json.put("FirmwareVersion", "version");
} catch (JSONException ex) {
} finally {
_callbackContext.success(json);
}
} catch (StarIOPortException e) {
_callbackContext.error("Failed to connect to printer :" + e.getMessage());
} finally {
if (port != null) {
try {
StarIOPort.releasePort(port);
} catch (StarIOPortException e) {
_callbackContext.error("Failed to connect to printer" + e.getMessage());
}
}
}
}
});
}
I identified (by comment / decomment) that my issue is caused by the getFirmwareInformation method, which it's called to get the ModelName and the FirmwareVersion.
It's a StarIO method, so I can't modify its behaviour.
I'm using this sample code:
With it, I want to get the status of a printer, and it works when there isn't any error on the printer (so when the cover is closed, the paper isn't empty and the cutter is ready).
But when I test to run this code when I open the cover, of anything that make the status offline, I get a StarIOPortException ('printer is offline') instead of the status with the flag corresponding to the offline causes.
To resolve that, in the file 'cordova-plugin-starprnt/src/android/StarPRNT.java', I tried to edit the checkStatus method :
I identified (by comment / decomment) that my issue is caused by the getFirmwareInformation method, which it's called to get the ModelName and the FirmwareVersion. It's a StarIO method, so I can't modify its behaviour.
Have you any ideas to solve this problem?