Android Question Decimal value send via BLE - long time


Licensed User
I have a text string from a HEX file (Intel format) with the following content: "02000C00189545" (txt file).
These are information about HEX values: 0x02 0x00 0x0C 0x18 0x95 0x45 and these are data intended for operations in the AVR microcontroller.
I divided the text string by 2 characters: 02 00 0C 00 18 95 45
Then I convert each of these parts to a DEC value
and in the next step I send each DEC value separately via BLE.

I do it in the following loop
Dim record As String
Dim Len_record As Int
Public sf As StringFunctions
Dim b As Byte
Dim a As String

record = "02000C00189545"
Len_record = record.Length

For z = 1 To Len_record - 1 Step 2
        a = sf.Mid(record, z, 2)       'separated to: 02 00 0C... in each step
        b = ( Bit.ParseInt(a,16) )      'converted to DEC value:  02-->2     00-->0   0C-->12...  in each step
       SendArray(b)      'each DEC value is sent separately     'send each DEC value

Public Sub SendArray (msg As Byte)
    manager.WriteData(ServiceId, WriteChar, Array As Byte(msg))
End Sub

The above solution works 100% but is very slow: A 2KB HEX file is sent to the CPU for about 5 minutes

I am still learning but I am convinced that sending the whole record will be much faster, but I do not know how to do it.

Principal question:
how to build such an array of DEC values
02 00 0C 00 18 95 45 ----> 2 0 12 0 24 -107 69
string -----> DEC
so that it can be sent with the SendArray function via BLE (also for B4i) to the processor ?
Perhaps I'm taking the wrong approach from the beginning, but I have failed with ByteBuilder and ByteConverter to solve it. I do not understand enough about the operation of these libraries.

Does anybody have an idea?

thanks for reading


Licensed User
Best way to convert hex string to bytes:
Dim bc As ByteConverter
Dim bytes() As Bytes = bc.HexToBytes(HexString)

And to send:
manager.WriteData(ServiceId, WriteChar, bytes)

Don't use StringFunctions. It is not needed.
Erel, thank you for your quick help.
Error-free program. An array with my data goes to the function.
The array is sent. Beautifully.

However, my Bluetooth module (HM-19 with CC26402RF on board) sends 0x00 value to the CPU via UART. And nothing more. :(
I do not understand this.

after a small modification, the table is correctly received by the BT module and the correct data runs to the CPU:
For i = 0 To bytes.Length -1
SendArray (bytes (i))

After testing, the HEX data transfer speed is much better. It's at a decent level and depends on the system speed of your phone.
Erel, thank you again. !!
Last edited:
Upvote 0