IPWorks BLE 2020 ActiveX Edition

Questions / Feedback?

Subscribe Method

Subscribes to value updates for the specified characteristic.

Syntax

bleclientcontrol.Subscribe ServiceId, CharacteristicId

Remarks

This method will subscribe the control to value updates for the characteristic whose Id is passed to CharacteristicId (which is owned by the service specified by ServiceId), as long as the characteristic supports it.

You can check a characteristic's CharacteristicCanSubscribe property to determine whether or not it supports subscriptions.

The Subscribed event will fire whenever you subscribe to a characteristic. While subscribed to a characteristic, the Value event will be fired each time the server sends an updated value for it (and its cached value will be updated as well).

The characteristic's CharacteristicSubscribed property can be used to determine whether or not the control is currently subscribed to a characteristic. You can also set it to true or false, which will automatically call Subscribe or Unsubscribe.

An error will be thrown if either of the given Ids are invalid, if the characteristic does not support subscribing for updates, or if there is an issue while trying to subscribe. Trying to subscribe to an already-subscribed characteristic does nothing.

Subscriptions

// Subscribed event handler.
bleclient1.OnSubscribed += (s, e) => {
  Console.WriteLine("Subscribed to characteristic:" +
    "\r\n\tID: " + e.CharacteristicId +
    "\r\n\tUUID: " + e.Uuid +
    "\r\n\tDescription: " + e.Description);
};
// Unsubscribed event handler.
bleclient1.OnUnsubscribed += (s, e) => {
  Console.WriteLine("Unsubscribed from characteristic:" +
    "\r\n\tID: " + e.CharacteristicId +
    "\r\n\tUUID: " + e.Uuid +
    "\r\n\tDescription: " + e.Description);
};
// Value event handler.
bleclient1.OnValue += (s, e) => {
  Console.WriteLine("Value update received for characteristic: " +
    "\r\n\tID: " + e.CharacteristicId +
    "\r\n\tUUID: " + e.Uuid +
    "\r\n\tDescription: " + e.Description +
    "\r\n\tValue: " + BitConverter.ToString(e.ValueB));
};

// Assume that we've already found the Luxometer Data characteristic,
// its owning service, and the Client Characteristic Configuration
// descriptor on it; and we've stored them in variables called "luxSvc",
// "luxData", and "luxCCCD".

// Subscribe and unsubscribe using methods.
bleclient1.Subscribe(luxSvc.Id, luxData.Id);
// ...
bleclient1.Unsubscribe(luxSvc.Id, luxData.Id);

// Subscribe and unsubscribe using the "Subscribed" field.
luxData.Subscribed = true;
// ...
luxData.Subscribed = false;

// Subscribe and unsubscribe by writing directly to the CCCD.
bleclient1.WriteValue(luxSvc.Id, luxData.Id, luxCCCD.Id, new byte[] { 1, 0 });
// ...
bleclient1.WriteValue(luxSvc.Id, luxData.Id, luxCCCD.Id, new byte[] { 0, 0 });

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