B4J Question How to close communication correctly?

kabron

Member
Licensed User
B4X:
Sub mnuClose_Action

    If astream.IsInitialized Then
    astream.Close
    serial.close      
    Else
    Msgbox.Show("No CommPort Selected", "ERROR")
    End If
End Sub
I get error messages on both commands:

for astream.close:
B4X:
java.lang.InterruptedException: sleep interrupted
    at java.lang.Thread.sleep(Native Method)
    at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:122)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.readNumberOfBytes(AsyncStreams.java:272)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:197)
    at java.lang.Thread.run(Thread.java:745)
and for serial.close:
B4X:
jssc.SerialPortException: Port name - COM7; Method name - getInputBufferBytesCount(); Exception type - Port not opened.
    at jssc.SerialPort.checkPortOpened(SerialPort.java:862)
    at jssc.SerialPort.getInputBufferBytesCount(SerialPort.java:786)
    at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:121)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.readNumberOfBytes(AsyncStreams.java:272)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:197)
    at java.lang.Thread.run(Thread.java:745)
java.lang.RuntimeException: jssc.SerialPortException: Port name - COM7; Method name - getInputBufferBytesCount(); Exception type - Port not opened.
    at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:129)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.readNumberOfBytes(AsyncStreams.java:272)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:197)
    at java.lang.Thread.run(Thread.java:745)
Caused by: jssc.SerialPortException: Port name - COM7; Method name - getInputBufferBytesCount(); Exception type - Port not opened.
    at jssc.SerialPort.checkPortOpened(SerialPort.java:862)
    at jssc.SerialPort.getInputBufferBytesCount(SerialPort.java:786)
    at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:121)
    ... 3 more
what is wrong? And how to do it correctly?
Thanks in advance
 

kabron

Member
Licensed User
Pardon, I found solution
Erel: "If you only see the InterruptedException message in the logs then you can ignore it."
 
Top