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
                });
            }
        }
Exemplo n.º 2
0
        public static void AssertWrite(this IGattCharacteristic characteristic, bool withResponse)
        {
            if (!characteristic.CanWrite())
            {
                throw new ArgumentException($"This characteristic '{characteristic.Uuid}' does not support writes");
            }

            if (withResponse && !characteristic.CanWriteWithResponse())
            {
                throw new ArgumentException($"This characteristic '{characteristic.Uuid}' does not support writes with response");
            }
        }
Exemplo n.º 3
0
        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;
                }
            }
        }