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“按钮时,我可以读取这个值。但是,如果我的值(角度)改变,它将不会自动更新通知用户。我必须手动单击“读”按钮再次更改。如何使它自动更新?
发布于 2018-05-24 06:36:52
您需要创建计时器线程来监视您的值的变化。
参见此计时器类
发布于 2018-05-24 16:38:47
为什么不设置您的RfDuino发送通知,如果这是可能的。
或者甚至把你的数据添加到广告中,这样就不需要连接了,只需要在OnAdvertisementReceived中加入。
在您的RfDuino中这样做:
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();
}如果您想发送新的数据呼叫:
// advertise "data" for indicated time
advertise("your data", duration);https://stackoverflow.com/questions/50501990
复制相似问题