Trouble parsing data from bluetooth

microbox

Active Member
Licensed User
Longtime User
I'm testing a simple application to receive data from mcu thru bluetooth...my trouble is parsing the data I need...bluetooth codes app I'm using is from this forum and modified a little. Please check codes I'm using..
Timer for checking data:
B4X:
Sub Timer1_Tick
   If connected Then
      If TextReader1.Ready Then 'check if there is any data waiting to be read
         txtLog.Text = txtLog.Text & TextReader1.ReadLine & CRLF
         BluetoothData = txtLog.Text          
         txtLog.SelectionStart = txtLog.Text.Length
         gotoread
      End If
   End If
End Sub
Function gotoread to display on EditTex
B4X:
Sub gotoread
    Dim List1 As List
    List1.Initialize
    Dim DataStart, DataEnd, EndIndex As Int 
    EndIndex = BluetoothData.LastIndexOf(":")        'end marker    
    DataStart = BluetoothData.IndexOf(":")
    DataEnd = BluetoothData.IndexOf2("Data",DataStart)
    Do While DataStart <> -1
       'Msgbox(BluetoothData.SubString2(DataStart + 1,DataEnd),"Data Value")
      numer1=BluetoothData.SubString2(DataStart + 1,DataEnd)
        List1.Add(BluetoothData.SubString2(DataStart + 1,DataEnd))
        DataStart = BluetoothData.IndexOf2(":",DataEnd)
      If DataStart <> EndIndex Then
            DataEnd = BluetoothData.IndexOf2("Data",DataStart)
        Else
            DataEnd = BluetoothData.Length
        End If
    Loop   
   EditText1.Text = List1.Get(0) 
   EditText2.Text = List1.Get(1)
   EditText3.Text = List1.Get(2)
   EditText4.Text = List1.Get(3)
End Sub
..and this the error I'm getting (please see attached image)
Hoping anyone can tell me what I'm doing wrong...appreciate your time.
 

Attachments

  • Pic3.jpg
    Pic3.jpg
    85.9 KB · Views: 164

microbox

Active Member
Licensed User
Longtime User
Somehow I manage to fix the error...by using
B4X:
If BluetoothData.Length > 10 Then 
'-- do something here--
End if
 
Upvote 0
Top