【发布时间】:2018-05-27 02:10:56
【问题描述】:
private async void Characteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
{
// BT_Code: An Indicate or Notify reported that the value has changed.
// Display the new value with a timestamp.
var newValue = FormatValueByPresentation(args.CharacteristicValue, presentationFormat);
var message = $"Value at {DateTime.Now:hh:mm:ss}: {newValue}";
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() => CharacteristicLatestValue.Text = message);
}
这是来自 github 的示例。通用 BluetoothLE 示例。我现在面临一个问题,如果我点击“阅读”按钮,它会显示我的 rfduino 阅读。但是因为我希望它在值更改时自动更新,所以我需要订阅值更改。
但是,当我单击“订阅值更改”时,我收到的只是“未知格式”。任何专家都可以帮助我逐步解决这个问题吗?如果可能,我们可以使用 Teamviewer。
private async void CharacteristicReadButton_Click()
{
// BT_Code: Read the actual value from the device by using Uncached.
GattReadResult result = await selectedCharacteristic.ReadValueAsync(BluetoothCacheMode.Uncached);
if (result.Status == GattCommunicationStatus.Success)
{
string formattedResult = FormatValueByPresentation(result.Value, presentationFormat);
rootPage.NotifyUser($"Read result: {formattedResult}", NotifyType.StatusMessage);
}
else
{
rootPage.NotifyUser($"Read failed: {result.Status}", NotifyType.ErrorMessage);
}
}
【问题讨论】:
标签: c# uwp bluetooth-lowenergy