B4J Question Is where any way to handle AsyncStream errors?

kabron

Member
Licensed User
Longtime User
I use AsyncStream in prefix mode. Everything is OK, but if I open serial port and it's input buffer already contains some data I naturally got application crash with diagnostic like:
"java.lang.NegativeArraySizeException" or similar.

So, I have to reopen port once again to establish connection.

Two questions arise:
1. Is there a way to clear port buffer inside the program before opening connection?
I do not think so.
I could clear it via opening e.g. some terminal emulator, but it is external effort.

2. Is there a way to prevent application crash and handle the error inside the program?

Thanks in advance.
 
Last edited:

kabron

Member
Licensed User
Longtime User
Thanks a lot, Erel. Now it's OK. One little unpleasant moment remained. After closing connection I always got a set of messages:

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:251)
    at java.lang.Thread.run(Thread.java:745)

It happens at astream.Close command.

I already raised this question long time ago. You told "it's OK don't worry". May be there is solution not to get this?
 
Upvote 0
Top