Android Question How to make Bytes packet from binary file

Hirogens

Active Member
Licensed User
Longtime User
Hello, I would like to know how can I divide a binary file in little bytes packet (divide to send to a device). And if possible with an adjustable packet size =)

Cordially
 

Didier9

Well-Known Member
Licensed User
Longtime User
Hello, I would like to know how can I divide a binary file in little bytes packet (divide to send to a device). And if possible with an adjustable packet size =)

Cordially
You probably do not need to do that, most network file transfer protocols will do that (split the file in packets of the right size for the protocol you are using) for you.
What protocol do you intend to use?
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
I try to send bytes by DFU. So I read a binary file (.dat) and try to split this file on bytes packets to send them.
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
Read the file with File.ReadBytes or [B4X] Bytes To File.

Add the bytes to BytesBuilder: https://www.b4x.com/android/forum/t...s-working-with-arrays-of-bytes.89008/#content

Use SubArray or SubArray2 to get the parts you need.

Hi Erel, I use this
B4X:
Sub ReadFile(Dir As String, FileName As String) As Byte()
    Dim out As OutputStream
    out.InitializeToBytesArray(100) 'size not really important
    File.Copy2(File.OpenInput(Dir, FileName), out)
    Return out.ToBytesArray
End Sub
With that
B4X:
byte_arr = ReadFile(shared, "file_name.dat")
This file_name contain my data. But I think the data which are return are not the same. I use NotePad++ to open my file and I think I have more data in :/

Question: How to use BytesBuilder ? It's not like a Library so where do I need to "include" it ? Because it's a class and I don't know how to use that in B4A :/
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
All the data is included. You can check the length with Log(byte_arr.Length).


Project - Add Existing Module.

It's work perfectly !
Now I have a problem with the communication between my device and B4A : Normally the device send some informations about his size, offset and CRC-32. But in the console log I can't catch this message, I only receive informations with this
B4X:
Public Sub DataAvailable(Services As String, Characteristics As Map)
log(Characteristics)
end sub
and that what I see
B4X:
(MyMap) {8ec90001-f315-4f60-9fb8-838830daea50=[B@db60187}
The fisrt part is my characteristic who send notification (Key if you prefer) and the last part is strange :/
Maybe I can modify the log to see more thing ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…