简体   繁体   English

无法订阅蓝牙低功耗中的通知特性

[英]Failed to subscribe to notification characteristic in bluetooth low energy

In my UWP application, I want to connect to a Bluetooth low energy peripheral device and subscribe to its notification characteristic.在我的 UWP 应用程序中,我想连接到低功耗蓝牙外围设备并订阅其通知特性。 this is the application Connect method:这是应用程序Connect方法:

private async Task Connect(string id)
{
    var device = await BluetoothLEDevice.FromIdAsync(id);
    var gattService = (await device.GetGattServicesForUuidAsync(Guid.Parse("00002600-005d-0012-00ef-00000000717f"))).Services.FirstOrDefault();
    if (gattService != null)
    {
        var notificationCharacteristic = (await gattService.GetCharacteristicsForUuidAsync(Guid.Parse("00009e76-0c4d-0db6-08b6-000000020445"))).Characteristics.FirstOrDefault();
        if (notificationCharacteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Notify))
        {
            try
            {
                var result = await notificationCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
            }
            catch (Exception ex)
            {

            }
        }
    }
}

The problem is when I try to write to the notification characteristic, the WriteClientCharacteristicConfigurationDescriptorAsync method raise an exception:问题是当我尝试写入通知特性时, WriteClientCharacteristicConfigurationDescriptorAsync方法引发异常:

The attribute cannot be written.无法写入该属性。 (Exception from HRESULT: 0x80650003) (来自 HRESULT 的异常:0x80650003)

I test this scenario using android application and I can write notification characteristic without any problem.我使用 android 应用程序测试了这个场景,我可以毫无问题地编写通知特性。 I want to know what the problem in UWP?我想知道 UWP 有什么问题?

Update: I change the UUID of notification characteristic descriptor from the peripheral device and see that the problem was solved.更新:我从外围设备更改了通知特征描述符的 UUID,发现问题已解决。

我发现了问题,经过一些测试,我从外围设备更改了通知特征描述符的UUID,看到问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM