B4J Question Problem with Serial and AsyncStreamsText

HARRY

Active Member
Licensed User
Longtime User
Hi,
My Raspberry communicates with an Arduino using USB. The B4J programm starts sending a request to the Arduino to supply date and time from a RTC connected to the Arduino. All communication is done in strings ending with CRLF.

After program start newdata is received ; sometimes with a length of 1 , sometimes with a length of e.g. 5129 bytes. Always unprintable characters.
Parts of the code is as follows:
B4X:
In Process_Globals
Dim Stream1 As AsyncStreamsText     'data from/ to Arduino via USB
Sub AppStart (Args() As String)
   
    sp.initialize("AStream")
    sp.Open("/dev/ttyUSB0")
    sp.SetParams(115200,8,1,0)
    Stream1.Initialize(Me,"Stream1",sp.GetInputStream,sp.GetOutputStream)
    RedirectOutput("/home/pi/MyApps/Domo", "logs.txt")   
    mcode=8
    Stream1.Write("8|3|"&CRLF)
    StartMessageLoop   
End Sub
Sub Stream1_NewText (Text As String)  'receive information from the Arduino node via USB
Dim requester As Int   
    Log(Text.Length)
    Log(Text)

I use the following libraries:
jSerial(Version 1.20)
jRandomAccessFile(Version 2.30)
jNetwork((Version 1.20)

B4J is version 5.80
AsynStreamsText version is 1.0

Working with other speeds makes no difference.

This strange behaviour is in Release mode as well as in Debug mode.

When I omit sending the request for date and time, other information from the Arduino is received correctly in Release mode. In Debug mode frequently the following error occurs: java.lang.RuntimeException: java.net.SocketException: Socket closed

Am I doing something wrong?
Harry
 
Top