Android Question Problem with Debug and AsyncStreams?

bstrable

Member
Licensed User
Longtime User
I am using AsyncStreams to receive data via a Bluetooth Serial connection. When I compile and run in "Release" mode, everything works like it should. I receive the data stream with no issues.
However, if I compile and run in "Debug" mode, I miss much of the data coming into the _NewData sub. Many of the bytes are just missing or not received. I tried Tools>Clean Project and removed all breakpoints, but no change. I am currently using v6.50 of B4A but it was written using v3.5 several years ago. (It worked fine then). The device I am using now is an Acer 7" running API 23.
Has anyone experienced this? Is there anything I can change to make it work again?
 

bstrable

Member
Licensed User
Longtime User
I have a motion controller connected to a RS232 to bluetooth adapter communicating at 9600 baud. The controller streams position information via Bluetooth to the Android tablet, terminated with a carriage return.

B4X:
Sub Process_Globals
    Dim CommBuffer As String
End Sub

Sub AStreams_NewData (Buffer() As Byte)
    Dim msg As String
    msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    CommBuffer = CommBuffer & msg
    If tmrSerialPoll.Enabled=True Then tmrSerialPoll_Tick
End Sub

Sub tmrSerialPoll_Tick
Dim f As Boolean
Dim p As Int
Dim Command As String
   
If CommBuffer.Length > 0 Then
    p=CommBuffer.IndexOf(Chr(13))
    If p > -1 Then
        Command = CommBuffer.SubString2(0,p)
        CommBuffer=CommBuffer.SubString(p+1)
    End If
End If
If Command.Length>0 Then
    Command=Command.Replace(Chr(10)," ")
    Command=Command.Replace(Chr(13)," ")
    Command=Command.Trim
           
    If Command.Length>2 Then
        f=ProcessCommand(Command)
    End If
End If
End Sub
 
Upvote 0

bstrable

Member
Licensed User
Longtime User
I modified my program to use the AsyncStreamsText Class, and I am still having the same issue. It works ok in release mode, but in debug it misses characters. To verify, I added Log(c) to the code below, and it is definitely missing characters. Is it possible the buffer there is a buffer overrun happening? I see no errors, is there a way to increase the bluetooth serial buffer?

B4X:
Private Sub astreams_NewData (Buffer() As Byte)
    Dim newDataStart As Int = sb.Length
    sb.Append(BytesToString(Buffer, 0, Buffer.Length, charset))
    Dim s As String = sb.ToString
    Dim start As Int = 0
    For i = newDataStart To s.Length - 1
        Dim c As Char = s.CharAt(i)
        Log(c)
 
Upvote 0

Tronak

Member
Licensed User
Longtime User
I have had a similar problem for a long time, independent of the B4A version. What I found useful was adding a useless program line in the NewData routine. Something like:
bolStream=asTextReport.IsInitialized.
If you run the program in debug mode, you comment (or uncomment) this line after installing, but before running the app in the device, and press Ctrl+S. Then the program runs without fail. It seems the fact of updating the code before running avoids triggering the error.
 
Upvote 0

bstrable

Member
Licensed User
Longtime User
Unfortunately, my employer will not allow me to upload the project, and I have not had the time to make an example project. However, I just discovered I can use the legacy debugger under Tools > IDE Options. This seems to work with no issues. I will just use the Legacy Debugger from now on.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…