I have been writing an b4j app to monitor various aspects of my network, this includes checking hardware is online, pinging servers etc. changes of status send messages via Firebase if there are changes... this is all working well except that if my internet connection dies firebase fails.. To overcome this I have utilised a cell modem plugged into a serial port to send sms messages if the internet fails, this uses Jserial and I have used try/end try to capture serial errors during initialisation however I cannot work out how to capture errors caused by the serial link disconnecting during use. for example if the USB cable becomes unplugged or the modem looses power.
The error is as below if this happens....
java.lang.NegativeArraySizeException: -1
at jssc.SerialNativeInterface.readBytes(Native Method)
at jssc.SerialPort.readBytes(SerialPort.java:437)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:165)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:157)
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:216)
at java.base/java.lang.Thread.run(Thread.java:834)
java.lang.RuntimeException: java.lang.NegativeArraySizeException: -1
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:172)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:157)
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:216)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NegativeArraySizeException: -1
at jssc.SerialNativeInterface.readBytes(Native Method)
at jssc.SerialPort.readBytes(SerialPort.java:437)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:165)
... 3 more
error: (NegativeArraySizeException) java.lang.NegativeArraySizeException: -1
Any suggestions will be gratefully accepted
The error is as below if this happens....
java.lang.NegativeArraySizeException: -1
at jssc.SerialNativeInterface.readBytes(Native Method)
at jssc.SerialPort.readBytes(SerialPort.java:437)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:165)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:157)
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:216)
at java.base/java.lang.Thread.run(Thread.java:834)
java.lang.RuntimeException: java.lang.NegativeArraySizeException: -1
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:172)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:157)
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:216)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NegativeArraySizeException: -1
at jssc.SerialNativeInterface.readBytes(Native Method)
at jssc.SerialPort.readBytes(SerialPort.java:437)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:165)
... 3 more
error: (NegativeArraySizeException) java.lang.NegativeArraySizeException: -1
Any suggestions will be gratefully accepted