iOS Question BLE get bytearray

Blueforcer

Well-Known Member
Licensed User
Longtime User
Hello,

ive wrote an App with B4A wich works perfect.
now i want to do the same with B4i.
I run B4i 3.5 with iBLE 2.00.

First i call ReadData and wait for DataAvailable.
Then i set a notify for a characteristic:
B4X:
manager.SetNotify("49535343-FE7D-4AE5-8FA9-9FAFD205E455","49535343-1E4D-4BD9-BA61-23C647249616",True)

After that i start a timer wich sends a special string to the device every 5 seconds

B4X:
    Dim s As String = "PCD-2 BLE"
        Main.manager.WriteData("49535343-FE7D-4AE5-8FA9-9FAFD205E455","49535343-8841-43F4-A8D4-ECBE34729BB3",s.GetBytes("UTF8"))

If the device recieve the String it will send back a bytearray.

Then the DataAvailable raise again because of the notify.
in B4i i get all characteristics instead of the single one i have set the notify to.

so now i want to read the bytearray in one characteristic:
B4X:
Sub DataAvailable (Service As String, Characteristics As Map)
    recievedData=True
        getPCDValues(Characteristics.Get(2))
    hd.ProgressDialogHide
End Sub

But the Characteristic is always NULL

This are all Characteristics and i want to read from [9] 49535343-1E4D-4BD9-BA61-23C647249616

B4X:
Notification state changed for characteristic: 49535343-1E4D-4BD9-BA61-23C647249616
NSMapTable {
[1] 49535343-ACA3-481C-91EC-D85E28A60318 -> <B4IArray: 0x15dcfad0>
[7] 49535343-6DAA-4D02-ABF6-19569ACA69FE -> <B4IArray: 0x15dd7530>
[9] 49535343-1E4D-4BD9-BA61-23C647249616 -> <B4IArray: 0x15dcd1e0>
[10] 49535343-8841-43F4-A8D4-ECBE34729BB3 -> <B4IArray: 0x15dd0920>
[12] 49535343-026E-3A9B-954C-97DAEF17E26E -> <B4IArray: 0x15dd9eb0>
}

What is the problem? Can somebody help me?
thanks!
 

Blueforcer

Well-Known Member
Licensed User
Longtime User
woah...i have mixed up "Characteristics.Get" and "Characteristics.GetValueAt ":)
thanks, now i get some data. but this is not the data i expected.

how must i handle this: <B4IArray: 0x17dd7c10>


in b4a i just do this:

B4X:
Sub DataAvailable (Service As String, Characteristics As Map)
    recievedData=True
    getPCDValues(Characteristics.GetValueAt(0))
End Sub

Sub getPCDValues(data() As Byte)
    'Aufsplitten des Byte-arrays
    cfg     =            Bit.And(data(0), 15)
    rx_mess =        Bit.And(data(0), 16)
    ph_mess =       Bit.And(data(0), 32)
    flow_mess =     Bit.And(data(0), 64)
    man_temp =     Bit.And(data(0), 128)
    des =               (pcdVal(data(1),data(2)))/100
    deswarn=         data(3)
    ph  =               (pcdVal(data(4),data(5)))/100
    phwarn=          data(6)
    rx  =                (pcdVal(data(7),data(8)))
    flow  =             (pcdVal(data(9),data(10)))
    flowwarn=        data(11)
    t0  =                (pcdVal(data(12),data(13)))/10
    t1  =                (pcdVal(data(14),data(15)))
    BuildPCDScreen
End Sub
 
Last edited:
Upvote 0
Top