B4J Question Reading from USB with AsyncStreamsText

Discussion in 'B4J Questions' started by HARRY, Mar 23, 2015.

  1. HARRY

    HARRY Active Member Licensed 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(24As 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the full error message (right click to copy it)?
     
  3. HARRY

    HARRY Active Member Licensed User

    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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is not clear from this error. Try to run it in Release mode and see whether you can reproduce this issue.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice