Asynchstreams Buffer access and clearing

rayzrocket

Member
Licensed User
Longtime User
How does the "Buffer() As Byte" data in the
"..._NewData" event get cleared after each use? :sign0104:
I have the Asynchstreams bluetooth demo working with a serial bluetooth device, but I cannot get values in the array beyond Buffer(0) assigned to a variable, as the following:

B4X:
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
Dim fred As Float
Dim wilma As Float
Dim barney As Float
fred = Buffer(0)
wilma = Buffer(1)
barney = Buffer(2)
[I]'wilma and barney code lines error in "out of bounds" fault on Buffer'[/I]
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")  
[I]'works great by showing all three characters recieved via bluetooth[/I]ToastMessageShow(msg, False)
Log(msg)
End Sub
:BangHead:

I'm using a PIC with HC-01 Bluetooth module and Samsung GalaxyII Skyrocket.
 

rayzrocket

Member
Licensed User
Longtime User
the incoming data was not always as expected so putting in some if then statements made the fix

but I still don't know what event exactly clears the buffer (obviously it gets cleared every time new data arrives, but then what is considered as new data?, is there a timeframe pause required between incoming bytes?)
B4X:
Sub AStreams_NewData (Buffer() As Byte)
   Dim Datapoint(2) As Float 'array of data at one time interval;
   Dim a1 As Int
   Dim k1 As Float
   Dim k2 As Float
   If Buffer.Length > 0 Then
      k1=Buffer(0)
      BTlabel2.Text=k1
   End If
   If Buffer.Length>1 Then
      k2=Buffer(1)
      BTlabel3.Text=k2
   End If
End Sub
 
Upvote 0

SHaque

New Member
I am working for a project in which my android device needs to receive large amount of data through Bluetooth connection.. I have used AsyncStream for receiving the data.. but every time some amount of data is getting lost.. Maybe due to the buffer size limitation.. So can anyone please help to solve this problem...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…