B4J Question Reading from USB with AsyncStreamsText

HARRY

Active Member
Licensed User
Longtime User
Hi,
I try to read from an USB port using AsyncStreamsText; but a strange error occurs.

The relevant code =

Code:
Sub Process_Globals
Dim sp As Serial
Dim AStream As AsyncStreamsText 
Dim BStream As AsyncStreamsText
Dim ss As ServerSocket
Dim cs As Socket
Type tablestruct ( year  As Int, month As Int, day As Int, gasconsumption As Long, elecconsumption As Long)
Dim  table(24) As tablestruct
End Sub

Sub AppStart (Args() As String)
Dim i As Int
    sp.initialize("aStream")
    Log(sp.ListPorts)
    sp.Open("/dev/ttyUSB0")
    sp.SetParams(9600,8,1,0)
    For    i=0 To 23
        table(i).Initialize
    Next
    AStream.Initialize(Me, "aStream",sp.GetInputStream,sp.GetOutputStream)
    ss.Initialize(40000,"ss")
    StartMessageLoop
End Sub

Sub aStream_NewText (Text As String)
    Log(Text)           
End Sub

BStream and ss have to do with another source.

After a while I get in the log Error occurred on line: 49 (main).

line 49 Reads: StartMessageLoop

What am I doing wrong?

Harry
 
Hi Erel,

In many cases the program, which is still under development, runs well. Occasionally this error occurs.
When it goes wrong then up till now I only got the error message : Error occurred on line: 49 (main); without further infomation.
Now I got an extensive description of what happened. This is the complete log:

Program started.
(ArrayList) [/dev/ttyAMA0, /dev/ttyUSB0]
Error occurred on line: 57 (main).
java.lang.RuntimeException: java.io.EOFException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:103)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:292)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.Shell
BA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:217)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 16 more

Can you explain what the cause of this error is?

Harry
 
Upvote 0
Back
Top