我正在尝试制作一个简单的UWP应用,该应用显示从心率监测器(Wahoo TICKR FIT)读取的值。我能够连接到显示器,但是无法访问HeartRateMeasurement特征的值。 GattReadResult的状态为ProtocolError,值为null。如何修复ProtocolError?
这一切都在使用Visual Studio 2017模板的普通UWP应用程序中完成。然后计划将工作代码转移到HoloLens项目中。
代码如下:
string btAddr = "F013C3B15603";
System.UInt64 addrInt = Convert.ToUInt64(btAddr, 16);
BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(addrInt);
string guidString = "0000180d-0000-1000-8000-00805f9b34fb"; // Armband HeartRate uuid
Guid guid = new Guid(guidString);
GattDeviceService gattService = device.GetGattService(guid);
// Try to access the characteristic we want
DeviceAccessStatus serviceAccessStatus = await gattService.RequestAccessAsync(); // allowed
GattOpenStatus openStatus = await gattService.OpenAsync(GattSharingMode.SharedReadAndWrite); // success
GattCharacteristicsResult results = await gattService.GetCharacteristicsAsync();
IReadOnlyList<GattCharacteristic> charList = results.Characteristics;
Debug.WriteLine(charList.Count); // should be 2
GattCharacteristic heartRateChar = charList[0];
Debug.WriteLine(heartRateChar.AttributeHandle); // should be 15
// Try to pull the heart rate data
GattCommunicationStatus commStatus = await heartRateChar.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify); // This works
GattReadResult heartRateResult = await heartRateChar.ReadValueAsync(BluetoothCacheMode.Uncached); // Status is ProtocolError (2)
问题最终出现在ReadValueAsync调用中。
答案 0 :(得分:0)
迈克·彼得里申科的评论就是解决方案。该特征不可读,我需要为ValueChanged事件创建一个事件处理程序方法,以接收传入的数据。