My Arduino Board sends for testing purpose incremented numbers by:
With the serial Monitor I can control the correct sending.
With a connect Button I open the connection:
My b4a-solution receives data:
But in most of the cases I get an 'error in main_astream_newdata' 'StringIndexOutofBoundsException'. I suppose, that this concern the index of Buffer(). Is the termination If Buffer(i)=13 correct or how to change it?
HTML:
Serial.println(Counter,DEC);
With a connect Button I open the connection:
HTML:
Sub BtnConnect_Click
If USB.UsbPresent = USB.USB_NONE Then
Msgbox("No USB device or accessory detected!", "Error")
Return
Else
If (USB.HasPermission) Then
Dim dev As Int
dev = USB.Open(9600)
If dev <> USB.USB_NONE Then
Log("Connected successfully!")
AStream.Initialize(USB.GetInputStream, USB.GetOutputStream, "AStream")
Else
Log("Error opening USB port")
End If
Else
USB.RequestPermission
End If
End If
End Sub
HTML:
Sub AStream_NewData (Buffer() As Byte)
temp=""
For i = 0 To Buffer.Length -1
If Buffer(i)=13 Then 'Zeilenende wg serial.println
Msgbox(temp,"von Arduino")
temp=""
Else
temp=temp&BytesToString(Buffer,i,Buffer.Length,"UTF8")
End If
Next
End Sub