首先,对不起我的英语不好。我正在研究UWP下的BluetoothLE。现在,我可以与我的蓝牙低能设备配对,我可以获得服务。然后,我想从我的蓝牙(LE)设备中获得所有的特性。
除了人机界面设备(HID)的特性外,我可以获得所有服务的特性。下面是代码获取特性(在combobox事件中更改服务时)。
private async void ServiceListCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var service = (GattDeviceService)((ComboBoxItem)ServiceListCombo.SelectedItem)?.Tag;
CharacteristicCombo.Items.Clear();
IReadOnlyList<GattCharacteristic> characteristics = null;
try
{
var accessStatus = await service.RequestAccessAsync();
if(accessStatus == DeviceAccessStatus.Allowed)
{
var result = await service.GetCharacteristicsAsync(BluetoothCacheMode.Uncached);
if(result.Status == GattCommunicationStatus.Success)
{
characteristics = result.Characteristics;
}
else
{
StatusTextBlock.Text = $"{result.Status.ToString()} // Failed";
characteristics = new List<GattCharacteristic>();
}
}
else
{
StatusTextBlock.Text = $"{accessStatus.ToString()} // Failed2";
characteristics = new List<GattCharacteristic>();
}
}
catch(Exception msg)
{
StatusTextBlock.Text = $"Exception : {msg.Message}";
characteristics = new List<GattCharacteristic>();
}
foreach(GattCharacteristic c in characteristics)
{
CharacteristicCombo.Items.Add(new ComboBoxItem { Content = Helpers.GetCharacteristicName(c), Tag = c });
}
CharacteristicCombo.Visibility = Visibility.Visible;
}我可以看到除HID之外的所有特征(状态:系统拒绝访问)
那么,我想知道的是,如何才能得到HID服务的特征。
我真的同意,如果你让我知道任何想法或建议。
谢谢。
https://stackoverflow.com/questions/68609267
复制相似问题