public override async void Prepare(MvxBundle parameters)
        {
            base.Prepare(parameters);

            _characteristic = await GetCharacteristicFromBundleAsync(parameters);

            Descriptors = await _characteristic?.GetDescriptorsAsync();

            RaisePropertyChanged(nameof(Descriptors));
        }
        protected override async void InitFromBundle(IMvxBundle parameters)
        {
            base.InitFromBundle(parameters);

            _characteristic = await GetCharacteristicFromBundleAsync(parameters);

            Descriptors = await _characteristic?.GetDescriptorsAsync();

            RaisePropertyChanged(nameof(Descriptors));
        }
예제 #3
0
        private async void btnDescriptors_Clicked(object sender, EventArgs e)
        {
            descriptors = await Characteristic.GetDescriptorsAsync();

            descriptor = await Characteristic.GetDescriptorAsync(Guid.Parse("guid"));
        }
        private async void InitalizeCommandButton_Clicked(object sender, EventArgs e)
        {
            try
            {
                var service = await _connectedDevice.GetServiceAsync(GattIdentifiers.UartGattServiceId);

                if (service != null)
                {
                    sendCharacteristic = await service.GetCharacteristicAsync(GattIdentifiers.UartGattCharacteristicSendId);

                    receiveCharacteristic = await service.GetCharacteristicAsync(GattIdentifiers.UartGattCharacteristicReceiveId);

                    if (receiveCharacteristic != null)
                    {
                        var descriptors = await receiveCharacteristic.GetDescriptorsAsync();

                        receiveCharacteristic.ValueUpdated += (o, args) =>
                        {
                            var receivedBytes = args.Characteristic.Value;
                            XamarinEssentials.MainThread.BeginInvokeOnMainThread(() =>
                            {
                                btdata += Encoding.UTF8.GetString(receivedBytes, 0, receivedBytes.Length); // + Environment.NewLine;
                                if (btdata.Substring(0, 3) != "EEE")
                                {
                                    btdata = null;
                                }

                                //----------Uncomment the lines below to display the Datas length-----------\\
                                //tring btData = receivedBytes.Length.ToString();
                                // RawData.Text = btdata;

                                //----------Uncomment the lines below to display the RawData----------\\
                                //RawData.Text = btdata;
                                var dataLength = btdata.Length;
                                if (dataLength >= 39 && (btdata.Substring(37, 2) == "GG"))     //Checks to make sure the recived data is the correct length
                                {
                                    dataParse();
                                    formatTheData();
                                    InitButton.BackgroundColor = Color.Transparent;
                                    btdata = null;          //Removes previous string after parsing data\
                                }
                                else if (dataLength >= 39)
                                {
                                    btdata = null;
                                }
                            });
                        };

                        await receiveCharacteristic.StartUpdatesAsync();

                        //  InitButton.IsEnabled = !(ScanButton.IsEnabled = true);
                    }
                }
                else
                {
                    // Output1.Text += "UART GATT service not found." + Environment.NewLine;
                }
            }
            catch
            {
                // Output1.Text += "Error initializing UART GATT service." + Environment.NewLine;
            }
        }