首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从BluetoothLEDevice中获取人机界面设备(HID)服务

如何从BluetoothLEDevice中获取人机界面设备(HID)服务
EN

Stack Overflow用户
提问于 2021-08-01 09:55:21
回答 1查看 118关注 0票数 0

首先,对不起我的英语不好。我正在研究UWP下的BluetoothLE。现在,我可以与我的蓝牙低能设备配对,我可以获得服务。然后,我想从我的蓝牙(LE)设备中获得所有的特性。

除了人机界面设备(HID)的特性外,我可以获得所有服务的特性。下面是代码获取特性(在combobox事件中更改服务时)。

代码语言:javascript
复制
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服务的特征。

我真的同意,如果你让我知道任何想法或建议。

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-02 03:17:15

除了人机界面设备(HID)的特性外,我可以得到所有的服务特性。

请检查文件这里。在支持蓝牙RFCOMM服务零件时,您会发现Human Interface Device不支持,恐怕您不能在your中获得hid设备特性,如果您确实需要此功能,请使用Windows免费发布您的要求。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68609267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档