Windows 10 Bluetooth Gatt Client ValueChanged issue

1.5k views Asked by At

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

There are 1 answers

0
rudi belt On
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);
        }