Android Question astreams-how do i clear a buffer

FFMan

Member
Licensed User
Longtime User
I'm using astreams to receive data over a Bluetooth link.

If the comms gets out of sync I need to clear the buffer, before I send another request for data. but I can't see how to clear the buffer, the astreams_newdata only fires when new data is received, if there is data in the buffer I want to discard how can I read this ?

thanks
 

KitCarlson

Active Member
Licensed User
Longtime User
I never clear the Buffer. I use
B4X:
b = b & BytesToString(Buffer, 0, Buffer.Length, "UTF8")
, then use IndexOf and SubString2 to parse the string, to pull out commands to process, and to clear used part of string.
 
Upvote 0

FFMan

Member
Licensed User
Longtime User
I think I get characters in the buffer when the app pauses and resumes, or when I kill and restart it, so there are characters in the buffer but the event doesn't fire. I need some way of clearing the buffer before I request new data, otherwise I guess I could code in a dummy request that causes a dummy return to fore the event.

just wondered if there was an easier way.
 
Upvote 0

KitCarlson

Active Member
Licensed User
Longtime User
Have you tried setting Buffer.Length to zero?

When possible, I like to use a protocol, to give identity to the request, and reply. It helps sort the handling for various processing needs.
 
Last edited:
Upvote 0
Top