private void SetUpdateValue(bool enable) { var success = _gatt.SetCharacteristicNotification(_nativeCharacteristic, enable); if (!success) { NotificationStateChanged?.Invoke(this, new CharacteristicNotificationStateEventArgs(this, false)); } if (_nativeCharacteristic.Descriptors.Count > 0) { const string descriptorId = "00002902-0000-1000-8000-00805f9b34fb"; var value = enable ? BluetoothGattDescriptor.EnableNotificationValue : BluetoothGattDescriptor.DisableNotificationValue; var descriptor = _nativeCharacteristic.Descriptors.FirstOrDefault(x => x.Uuid.ToString() == descriptorId); if (descriptor != null && !descriptor.SetValue(value.ToArray())) { throw new Exception("Unable to set the notification value on the descriptor"); } var dSuccess = _gatt.WriteDescriptor(descriptor); if (!dSuccess) { //NotificationStateChanged?.Invoke(this, new CharacteristicNotificationStateEventArgs(this, false)); } } _isUpdating = enable; }
private void OnDescriptorWriteComplete(object sender, DescriptorWriteEventArgs descriptorWriteEventArgs) { if (descriptorWriteEventArgs.CharacteristicId == this.Id) { const string descriptorId = "00002902-0000-1000-8000-00805f9b34fb"; if (descriptorWriteEventArgs.DescriptorId.ToString() == descriptorId) { NotificationStateChanged?.Invoke(this, new CharacteristicNotificationStateEventArgs(this, true)); } DescriptorWriteComplete?.Invoke(this, descriptorWriteEventArgs); } }
private void PeripheralOnUpdatedNotificationState(object sender, CBCharacteristicEventArgs cbCharacteristicEventArgs) { NotificationStateChanged?.Invoke(this, new CharacteristicNotificationStateEventArgs(this, cbCharacteristicEventArgs.Error == null)); }