Windows 10 Bluetooth Gatt Client ValueChanged issue

霸气de小男生 提交于 2019-12-24 04:34:07

问题


I'm having an issue with Bluetooth Gatt characteristic reading at the moment. I was trying to run the code with my own custom profile

thermometerCharacteristic.ValueChanged += temperatureMeasurementChanged;

It causes this exception

An exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: Value does not fall within the expected range.

My function arguments looks like this

void temperatureMeasurementChanged(GattCharacteristic sender, GattValueChangedEventArgs eventArgs)

This code resembles the sample to retrieve Bluetooth LE data on MSDN. Any ideas on what could cause this? Thanks so much!


回答1:


Check for thermometerCharacteristic.CharacteristicProperties == (GattCharacteristicProperties.Read | GattCharacteristicProperties.Notify)

before subscribing:

     if (characteristic.CharacteristicProperties == (GattCharacteristicProperties.Read | GattCharacteristicProperties.Notify))
        {
            characteristic.ValueChanged += Characteristic_ValueChanged;

            GattCommunicationStatus status =
                       await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(
                       CHARACTERISTIC_NOTIFICATION_TYPE);
        }


来源:https://stackoverflow.com/questions/30983568/windows-10-bluetooth-gatt-client-valuechanged-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!