在UWP中启用多个BLE特性通知

时间:2017-04-14 10:54:42

标签: c# uwp

我尝试在我的UWP应用程序中启用2通知,但每次只有第一个特征通知用户。

    AccessConfigurationCharacteristic();
                ConfigurationselectedCharacteristic = selectedCharacteristic;
                CharacteristicNotifyEnableForConfig();

                await Task.Delay(5000);

                AccessDiagnosticCharacteristic();
                DiagnosticselectedCharacteristic = selectedCharacteristic;
                CharacteristicNotifyEnable();

  private async void CharacteristicNotifyEnable()
        {
            try
            {
                // BT_Code: Must write the CCCD in order for server to send notifications.
                // We receive them in the ValueChanged event handler.
                // Note that this sample configures either Indicate or Notify, but not both.
                var result = await
                        DiagnosticselectedCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(
                            GattClientCharacteristicConfigurationDescriptorValue.Notify);
                if (result == GattCommunicationStatus.Success)
                {
                    AddValueChangedHandler();
                    // rootPage.NotifyUser("Successfully registered for notifications", NotifyType.StatusMessage);
                }
                else
                {

                    //  rootPage.NotifyUser($"Error registering for notifications: {result}", NotifyType.ErrorMessage);
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                // This usually happens when a device reports that it support notify, but it actually doesn't.
              //  rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
            }
        }

'CharacteristicsNotifyEnableForConfig()'方法类似于CharacteristicsNotifyEnable()但具有不同的特征。任何人都可以帮我解决。

0 个答案:

没有答案