public static void AssertRead(this IGattCharacteristic characteristic) { if (!characteristic.CanRead()) { throw new ArgumentException($"This characteristic '{characteristic.Uuid}' does not support reads"); } }
public CharacteristicEditPage(IGattCharacteristic selectedCharacteristic) { InitializeComponent(); Title = selectedCharacteristic.Uuid.ToString(); if (selectedCharacteristic.CanRead()) { ReadCharacteristicAsync(selectedCharacteristic); } if (selectedCharacteristic.CanWrite()) { //await Characteristic.Write(bytes); } if (selectedCharacteristic.CanNotify()) { // TODO: couldn't get this to work for the demo. // The docs show this, but SetNotificationValue() doesn't exist in IGattCharacteristic //var success = selectedCharacteristic.SetNotificationValue(CharacteristicConfigDescriptorValue.Notify); // TODO: this didn't seem to do much selectedCharacteristic.SubscribeToNotifications(); selectedCharacteristic.WhenNotificationReceived().Subscribe(result => { //result.Data }); } }
public static IObservable <byte[]> WhenReadOrNotify(this IGattCharacteristic character, TimeSpan readInterval) { if (character.CanNotify()) { return(character.SubscribeToNotifications()); } if (character.CanRead()) { return(character.ReadInterval(readInterval)); } throw new ArgumentException($"Characteristic {character.Uuid} does not have read or notify permissions"); }
public static IObservable <CharacteristicResult> WhenReadOrNotify(this IGattCharacteristic character, TimeSpan readInterval) { if (character.CanNotify()) { return(character .EnableNotifications() .Where(x => x) .Select(x => character.WhenNotificationReceived()) .Switch()); } if (character.CanRead()) { return(character.ReadInterval(readInterval)); } throw new ArgumentException($"Characteristic {character.Uuid} does not have read or notify permissions"); }
private void ListView_ItemTapped(object sender, ItemTappedEventArgs e) { var select = (CharacteristicsList)e.Item; foreach (var c in AllCharacteristics) { if (c.Uuid == select.Uuid) { SelectCharacteristic = c; info_uuid.Text = "UUID:" + SelectCharacteristic.Uuid; info_read.Text = "CallBack UUID:"; notify_btn.Text = "Notify"; if (SelectCharacteristic.CanRead()) { read_btn.IsVisible = true; } else { read_btn.IsVisible = false; } if (SelectCharacteristic.CanWrite()) { write_btn.IsVisible = true; } else { write_btn.IsVisible = false; } if (SelectCharacteristic.CanNotify()) { notify_btn.IsVisible = true; } else { notify_btn.IsVisible = false; } background.IsVisible = true; info.IsVisible = true; break; } } }