WriteValue Method
Write the value of a characteristic or descriptor.
Syntax
Remarks
This method is used to write the value of a characteristic or descriptor. The method will return and the WriteResponse event will fire if the write is a success. If the write fails, the Error event will fire and the component throws an exception.
To write the value of a characteristic, pass the Ids of it and its owning service for the CharacteristicId and ServiceId parameters, and pass empty string for the DescriptorId parameter. To write the value of a descriptor, do the same thing, but pass the descriptor's Id for the DescriptorId parameter too.
If your use-case doesn't require confirmation of characteristic value writes, prefer the PostValue method in order to reduce power consumption.
Writing Values
// WriteResponse event handler.
bleclient1.OnWriteResponse += (s, e) => {
if (string.IsNullOrEmpty(e.DescriptorId)) {
Console.WriteLine("Successfully wrote to characteristic with UUID " + e.Uuid);
} else {
Console.WriteLine("Successfully wrote to descriptor with UUID " + e.Uuid);
}
};
// Write to the Luxometer Config characteristic. These Ids are correct
// for our CC2650STK TI SensorTag, but yours might differ.
bleclient1.WriteValue("004200000000", "004200460000", "", new byte[] { 0x1 });
// Write to the Client Characteristic Configuration descriptor on the
// Luxometer Data characteristic. Again, your Ids might differ.
bleclient1.WriteValue("004200000000", "004200430000", "004200430045", new byte[] { 0x1 });