Newbie to B4J. I made a small program receiving data from an arduino on serial port. Code below works for a while and then crashes:
LOG :
Program started.
data ERROR
data OK
GRUND
36.00
21.00
data OK
Sensor 1
GRUND
36.00
21.00
data ERROR
data OK
GRUND
36.00
21.00
Error occurred on line: 60 (main).
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:334)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:166)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at com.sun.javafx.application.PlatformImpl$4$1.run(Unknown Source)
at com.sun.javafx.application.PlatformIm
pl$4$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
at b4j.example.main._astream_newdata(main.java:183)
... 23 more
Can someone give a hint how to catch serial data in a robust way.
BTW awesome software when you get the hang of it ! Thank's
Regards Håkan
B4X:
Sub AStream_NewData (Buffer() As Byte)
'***********************************************
Dim inputdata As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Dim node_id As String
Dim node_location As String
Dim data_1 As String
Dim data_2 As String
'Dim OutList As List
Dim NL As String
NL = Chr(13)& Chr(10)
'**************************
If inputdata.EndsWith(NL) Then
Log("data OK")
Dim OutList() As String = (Regex.Split(",", inputdata))
node_id = OutList(0)
Log(node_id)
node_location = OutList(1)
Log(node_location)
data_1 = OutList(2)
Log(data_1)
data_2 = OutList(3)
Log(data_2)
Else
Log("data ERROR")
End If
'Log(OutList)
End Sub
LOG :
Program started.
data ERROR
data OK
GRUND
36.00
21.00
data OK
Sensor 1
GRUND
36.00
21.00
data ERROR
data OK
GRUND
36.00
21.00
Error occurred on line: 60 (main).
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:334)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:166)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at com.sun.javafx.application.PlatformImpl$4$1.run(Unknown Source)
at com.sun.javafx.application.PlatformIm
pl$4$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
at b4j.example.main._astream_newdata(main.java:183)
... 23 more
Can someone give a hint how to catch serial data in a robust way.
BTW awesome software when you get the hang of it ! Thank's
Regards Håkan
Last edited: