does your recipient need a special format? you need to prepare it?
basically data are just bytes but you can wrap all content in a struct as example json,xml.
you need to know what the other side will see.
high transfer rate can affect data loss.
Thanks for the question. I’m actually stuck at the fundamentals, I’ve figured out how to read, but can’t seem to figure out how to address the GATT characteristics and actually call the write method.
Ie, I assume it’s something like this:
devices(0).GattServices(0).Characteristics(0).writevalue(MB)
but you know what they say about assumptions…
Ie, it’s not that it’s not actually working, I just don’t know how to even try to send data. My device is a custom microcontroller and I’m just sending a few bytes from a memoryblock for now.
More than happy if an admin wants to pop it in the Add-ons section. I guess my question might be a little generic in that I’m trying to figure out how to call those methods… Ie, what the code looks like to reference the plugin in the most basic form.
Well, this is a multi step process with async events.
Since you can read, I assume you got the WindowsGattCharacteristicMBS object. Then maybe query the WindowsGattDescriptorMBS like in the BluetoothLE Device example.
And it is probably important to keep references to the objects over time. Like if you call WriteValueAsync and the object is destroyed at the end of the method, the async process could get cancelled.
As said, I wrote this with a few customers together and I’ll ask them for an example.
So you got the WindowsGattDeviceServiceMBS object, either by picking from the array you got via GetGattServicesCompleted or IncludedServicesCompleted events.
Then you would query the characteristics, e.g.
me.GetCharacteristicsAsync(Me.CacheModeCached)
once you got CharacteristicsCompleted event, you can make new objects of your WindowsGattCharacteristicMBS subclass to catch events and then sends values:
Sub CharacteristicsCompleted(asyncStatus as Integer, Result as WindowsGattCharacteristicsResultMBS) Handles CharacteristicsCompleted
Log CurrentMethodName
If result <> Nil Then
Dim theCharacteristics() As WindowsGattCharacteristicMBS = Result.Characteristics
For Each theCharacteristic As WindowsGattCharacteristicMBS In theCharacteristics
Dim Characteristic As New GattCharacteristic(theCharacteristic)
Log "Characteristic: "+Characteristic.UserDescription+" "+Characteristic.UUID
Characteristics.append Characteristic
Characteristic.GetDescriptorsAsync
Next
Characteristics(1).WriteClientCharacteristicConfigurationDescriptorAsync(1)
Var mb As New MemoryBlock(6)
mb.Byte(0) = &H01 // Data Byte
mb.Byte(1) = &HAA
mb.Byte(2) = &H55
mb.Byte(3) = &HAA
mb.Byte(4) = &H55
mb.Byte(5) = &HAA
Characteristics(0).WriteValueAsync(mb, GattCharacteristic.WriteWithResponse)
Else
Log "Failed to get characteristics."
End If
End Sub
For this example there are two characteristics. First it sets configuration descriptor to 1, which I think is WriteWithoutResponse.
Then it assembles a data package with 6 bytes and writes it.
Later the WriteValueAsyncCompleted event is called.
James, I am starting a new LE project and if you have sample code to share now for characteristic read and write it sounds like that would jump start my work. Thanks. David