首页 > 解决方案 > Plugin.BLE(1.3.0) for xamarin.Forms 没有在特征中获取数据字节

问题描述

我正在开发表单应用程序,我正在连接到设备并需要获取数据。我能够搜索设备、连接并获取服务,但对于服务,我无法从其特性中读取数据。

 Services = await device.GetServicesAsync();
                try
                {
                    selectedServiceGuid = Services[6].Id;
                    Service = await device.GetServiceAsync(selectedServiceGuid);    
                }
                catch (TimeoutException ext)
                {
                }
                catch (Exception ex)
                {
                } 

                Characteristic = await Service.GetCharacteristicAsync(Guid.Parse("f000aa41-0451-4000-b000-000000000000")); 

                if (Characteristic.CanRead)
                {
                    var c = await Characteristic.ReadAsync();
                    Console.WriteLine(c.ToArray());
                }

                if (Characteristic.CanUpdate)
                {
                    Characteristic.ValueUpdated += (s, ee) =>
                    {
                        Debug.WriteLine("characteristic.ValueUpdated");
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            UpdateDisplay(Characteristic);
                        });
                    };
                  await  Characteristic.StartUpdatesAsync();

                }

在所有索引处获取 byte[] 0,使用 await Characteristic.ReadAsync() 读取。任何人都面临/面临同样的问题?

标签: c#xamarin.formsnugetbluetooth-lowenergy

解决方案


推荐阅读