/// <summary> /// Initializes a new instance of the<see cref="ObservableGattDescriptors" /> class. /// </summary> /// <param name="descriptor">Descriptor this class wraps</param> /// <param name="parent">The parent service that wraps this characteristic</param> public ObservableGattDescriptors(GattDescriptor descriptor, ObservableGattCharacteristics parent) { Descriptor = descriptor; Parent = parent; Name = GattDescriptorUuidHelper.ConvertUuidToName(descriptor.Uuid); UUID = descriptor.Uuid.ToString(); }
/// <summary> /// Gets all the characteristics of this service /// </summary> 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; } GattCharacteristicsResult 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; } }
/// <summary> /// Initializes a new instance of the<see cref="ObservableGattDescriptors" /> class. /// </summary> /// <param name="descriptor">Descriptor this class wraps</param> /// <param name="parent">The parent service that wraps this characteristic</param> public ObservableGattDescriptors(GattDescriptor descriptor, ObservableGattCharacteristics parent) { Descriptor = descriptor; Parent = parent; Name = GattDescriptorUuidHelper.ConvertUuidToName(Descriptor.Uuid); UUID = Descriptor.Uuid.ToString(); ReadValueAsync(); PropertyChanged += ObservableGattDescriptors_PropertyChanged; }
/// <summary> /// Initializes a new instance of the<see cref="ObservableGattDescriptors" /> class. /// </summary> /// <param name="descriptor">Descriptor this class wraps</param> /// <param name="parent">The parent service that wraps this characteristic</param> public ObservableGattDescriptors(GattDescriptor descriptor, ObservableGattCharacteristics parent) { Descriptor = descriptor; Parent = parent; }