首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取值自动更新UWA/UWP

读取值自动更新UWA/UWP
EN

Stack Overflow用户
提问于 2018-05-24 06:00:35
回答 2查看 119关注 0票数 2
代码语言:javascript
复制
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);
    }
}

我正面临着阅读值改变的问题。我用我的rfduino设置了mpu5060,所以每当我的rfduino移动时,它就会在我的Arduino系列监视器上显示角度。

对于我的c#,当我按下" read“按钮时,我可以读取这个值。但是,如果我的值(角度)改变,它将不会自动更新通知用户。我必须手动单击“读”按钮再次更改。如何使它自动更新?

EN

回答 2

Stack Overflow用户

发布于 2018-05-24 06:36:52

您需要创建计时器线程来监视您的值的变化。

参见此计时器类

票数 1
EN

Stack Overflow用户

发布于 2018-05-24 16:38:47

为什么不设置您的RfDuino发送通知,如果这是可能的。

或者甚至把你的数据添加到广告中,这样就不需要连接了,只需要在OnAdvertisementReceived中加入。

在您的RfDuino中这样做:

代码语言:javascript
复制
void advertise(const char *data, uint32_t ms)
{
  // this is the data we want to appear in the advertisement
  // /make sure that the RfDuino name + data is not more than 31 bytes
  RFduinoBLE.advertisementData = data;

  // start the BLE stack
  RFduinoBLE.begin();

  // advertise for ms milliseconds
  RFduino_ULPDelay(ms);

  // stop the BLE stack
  RFduinoBLE.end();
}

如果您想发送新的数据呼叫:

代码语言:javascript
复制
// advertise "data" for indicated time
advertise("your data", duration);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50501990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档