H Hirogens Active Member Licensed User Longtime User Jun 6, 2018 #1 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
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 Jun 7, 2018 #2 Hirogens said: 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 Click to expand... 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 said: 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 Click to expand... 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?
H Hirogens Active Member Licensed User Longtime User Jun 7, 2018 #3 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
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.
Erel B4X founder Staff member Licensed User Longtime User Jun 7, 2018 #4 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. Upvote 0
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.
H Hirogens Active Member Licensed User Longtime User Jun 7, 2018 #5 Erel said: 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. Click to expand... Hi Erel, I use this Code: Copy 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 Code: Copy 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
Erel said: 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. Click to expand... Hi Erel, I use this Code: Copy 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 Code: Copy 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 :/
Erel B4X founder Staff member Licensed User Longtime User Jun 7, 2018 #6 All the data is included. You can check the length with Log(byte_arr.Length). Hirogens said: Question: How to use BytesBuilder ? Click to expand... Project - Add Existing Module. Upvote 0
All the data is included. You can check the length with Log(byte_arr.Length). Hirogens said: Question: How to use BytesBuilder ? Click to expand... Project - Add Existing Module.
H Hirogens Active Member Licensed User Longtime User Jun 7, 2018 #7 Erel said: All the data is included. You can check the length with Log(byte_arr.Length). Project - Add Existing Module. Click to expand... 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 Code: Copy Public Sub DataAvailable(Services As String, Characteristics As Map) log(Characteristics) end sub and that what I see Code: Copy (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
Erel said: All the data is included. You can check the length with Log(byte_arr.Length). Project - Add Existing Module. Click to expand... 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 Code: Copy Public Sub DataAvailable(Services As String, Characteristics As Map) log(Characteristics) end sub and that what I see Code: Copy (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 ?
DonManfred Expert Licensed User Longtime User Jun 7, 2018 #8 Hirogens said: and the last part is strange :/ Click to expand... no, it is a bytearray something like Code: Copy dim value() As Byte = Characteristics.Get("8ec90001-f315-4f60-9fb8-838830daea50") Upvote 0
Hirogens said: and the last part is strange :/ Click to expand... no, it is a bytearray something like Code: Copy dim value() As Byte = Characteristics.Get("8ec90001-f315-4f60-9fb8-838830daea50")
Erel B4X founder Staff member Licensed User Longtime User Jun 7, 2018 #9 You can also use ByteConverter.HexFromBytes to convert the array of bytes to a hex string. For further discussion please start a new thread. Upvote 0
You can also use ByteConverter.HexFromBytes to convert the array of bytes to a hex string. For further discussion please start a new thread.