in BluetoothLEExplorer/BluetoothLEExplorer/Models/ObservableGattCharacteristics.cs [501:552]
public async Task<bool> SetIndicate()
{
if (IsIndicateSet == true)
{
// already set
return true;
}
try
{
// BT_Code: Must write the CCCD in order for server to send indications.
// We receive them in the ValueChanged event handler.
// Note that this sample configures either Indicate or Notify, but not both.
var result = await
characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(
GattClientCharacteristicConfigurationDescriptorValue.Indicate);
if (result == GattCommunicationStatus.Success)
{
Debug.WriteLine("Successfully registered for indications");
IsIndicateSet = true;
return true;
}
else if (result == GattCommunicationStatus.ProtocolError)
{
Debug.WriteLine("Error registering for indications: Protocol Error");
IsIndicateSet = false;
return false;
}
else if (result == GattCommunicationStatus.Unreachable)
{
Debug.WriteLine("Error registering for indications: Unreachable");
IsIndicateSet = false;
return false;
}
}
catch (UnauthorizedAccessException ex)
{
// This usually happens when a device reports that it support indicate, but it actually doesn't.
Debug.WriteLine("Unauthorized Exception: " + ex.Message);
IsIndicateSet = false;
return false;
}
catch (Exception ex)
{
Debug.WriteLine("Generic Exception: " + ex.Message);
IsIndicateSet = false;
return false;
}
IsIndicateSet = false;
return false;
}