IPWorks BLE 2020 ActiveX Edition

Questions / Feedback?

WriteValue Method

Write the value of a characteristic or descriptor.

Syntax

bleclientcontrol.WriteValue ServiceId, CharacteristicId, DescriptorId, Value

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 control fails with an error.

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 });

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks BLE 2020 ActiveX Edition - Version 20.0 [Build 8162]