Android Question Binary Data Stream via Bluetooth

PhilipK

Member
Licensed User
Longtime User
Hi

I'm receiving a data stream through Bluetooth which has the following format:

Header bytedata1data2data3...dataNchecksum
The header is a single byte, the data length is between 1 and 255 bytes depending on the type of message and the checksum is a single byte.


Please could you give an example of how to read and convert the stream into bytes? Is there a B4A library with function(s) or copy array method?

Connecting to data stream using an inputstream:

Stream.Initialize(Serial1.InputStream,Serial1.OutputStream, "Stream")

Sub Stream_NewData (Buffer() As Byte)
....

Thanks in advance.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please could you give an example of how to read and convert the stream into bytes?
It is already an array of bytes.
Buffer(0) will return the first byte.

However you shouldn't expect messages to arrive as a single packet (in non-prefix mode).
You should create a large array of bytes and copy the new data to this array. Once you have a full message in the large array you should process it and trim the array.

Example: https://www.b4x.com/android/forum/threads/b4x-class-mjpeg-decoder.73702/#content
 
Upvote 0
Top