in BluetoothLEExplorer/BluetoothLEExplorer/Models/ObservableGattDeviceService.cs [423:475]
private async Task GetAllCharacteristics()
{
StringBuilder sb = new StringBuilder();
sb.Append("ObservableGattDeviceService::getAllCharacteristics: ");
sb.Append(name);
try
{
// Request the necessary access permissions for the service and abort
// if permissions are denied.
GattOpenStatus status = await service.OpenAsync(GattSharingMode.SharedReadAndWrite);
if (status != GattOpenStatus.Success && status != GattOpenStatus.AlreadyOpened)
{
string error = " - Error: " + status.ToString();
Name += error;
sb.Append(error);
Debug.WriteLine(sb.ToString());
return;
}
var result = await service.GetCharacteristicsAsync(Services.SettingsServices.SettingsService.Instance.UseCaching ? BluetoothCacheMode.Cached : BluetoothCacheMode.Uncached);
if (result.Status == GattCommunicationStatus.Success)
{
sb.Append(" - getAllCharacteristics found ");
sb.Append(result.Characteristics.Count());
sb.Append(" characteristics");
Debug.WriteLine(sb);
foreach (GattCharacteristic gattchar in result.Characteristics)
{
ObservableGattCharacteristics temp = new ObservableGattCharacteristics(gattchar, this);
await temp.Initialize();
Characteristics.Add(temp);
}
}
else if (result.Status == GattCommunicationStatus.Unreachable)
{
sb.Append(" - getAllCharacteristics failed with Unreachable");
Debug.WriteLine(sb.ToString());
}
else if (result.Status == GattCommunicationStatus.ProtocolError)
{
sb.Append(" - getAllCharacteristics failed with Unreachable");
Debug.WriteLine(sb.ToString());
}
}
catch (Exception ex)
{
Debug.WriteLine("getAllCharacteristics: Exception - {0}" + ex.Message);
Name += " - Exception: " + ex.Message;
}
}