BLE,订阅2个Characterisitics通知无效。只为一个人工作

时间:2016-10-26 23:23:38

标签: android notifications bluetooth-lowenergy gatt characteristics

我成功为我的Android应用程序编写代码,目的是从我的BLE设备读取特征值,然后激活与此特性相关的通知,以便在我的应用程序中显示更新的值。 该应用程序运行良好。

但是当我尝试激活第二个特征的通知时,通知仅适用于一个特征,而不适用于两者。

所以我们称之为第一个特征'Date_time_Characteristic',第二个'nbr_sample_Characteristic'

我注意到以下内容:如果我订阅了'Date_time_Characteristic'的通知,然后我订阅'nbr_sample_Characteristic',则只有订阅的第一个会生成通知。在这种情况下,'Date_time_Characteristic'

            // set notification for Date time Characteristic
        Console.WriteLine("Charac Uuid =  " + _charac_DateTime.Uuid);
        BluetoothLEManager.Current.ConnectedDevices[App.Current.State.SelectedDevice].SetCharacteristicNotification(_charac_DateTime, true);
        BluetoothGattDescriptor descriptor = _charac_DateTime.GetDescriptor(Descr_UUID);
        Console.WriteLine("descriptor : " + descriptor.Uuid);
        descriptor.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray());
        BluetoothLEManager.Current.ConnectedDevices[App.Current.State.SelectedDevice].WriteDescriptor(descriptor);


        // set notification for nbr sample Characteristic
        BluetoothLEManager.Current.ConnectedDevices[App.Current.State.SelectedDevice].SetCharacteristicNotification(_charac_NbrSample, true);
        BluetoothGattDescriptor descriptor2 = _charac_NbrSample.GetDescriptor(Descr_UUID);
        descriptor2.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray());
        BluetoothLEManager.Current.ConnectedDevices[App.Current.State.SelectedDevice].WriteDescriptor(descriptor2);

如果我执行相反操作并首先订阅'nbr_sample_Characteristic',则只有'nbr_sample_Characteristic'会生成通知并更新其值。

            // set notification for nbr sample Characteristic
        BluetoothLEManager.Current.ConnectedDevices[App.Current.State.SelectedDevice].SetCharacteristicNotification(_charac_NbrSample, true);
        BluetoothGattDescriptor descriptor2 = _charac_NbrSample.GetDescriptor(Descr_UUID);
        descriptor2.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray());
        BluetoothLEManager.Current.ConnectedDevices[App.Current.State.SelectedDevice].WriteDescriptor(descriptor2);

        // set notification for Date time Characteristic
        Console.WriteLine("Charac Uuid =  " + _charac_DateTime.Uuid);
        BluetoothLEManager.Current.ConnectedDevices[App.Current.State.SelectedDevice].SetCharacteristicNotification(_charac_DateTime, true);
        BluetoothGattDescriptor descriptor = _charac_DateTime.GetDescriptor(Descr_UUID);
        Console.WriteLine("descriptor : " + descriptor.Uuid);
        descriptor.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray());
        BluetoothLEManager.Current.ConnectedDevices[App.Current.State.SelectedDevice].WriteDescriptor(descriptor);

如何解决此问题并让这两个特性通知应用?

0 个答案:

没有答案