[英]Get Heart Rate From Microsoft Band
I am trying to get the heart rate from a Microsoft Band. 我试图从微软乐队获得心率。 It should be updating whenever the value changes. 只要值发生变化,它就应该更新。 I am then trying to display that value in a TextBlock
. 然后我尝试在TextBlock
显示该值。 I first create an instance of IBandClient
, and set its HeartRate.ReadingChanged
method like this: 我首先创建一个IBandClient
实例,并设置其HeartRate.ReadingChanged
方法,如下所示:
bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
Then I try to update the value like this: 然后我尝试像这样更新值:
private void HeartRate_ReadingChanged(object sender, Microsoft.Band.Sensors.BandSensorReadingEventArgs<Microsoft.Band.Sensors.IBandHeartRateReading> e)
{
HeartRate = e.SensorReading.HeartRate;
}
HeartRate is an int
set like so: HeartRate是这样的int
集合:
public int HeartRate
{
get { return (int)GetValue(HeartRateProperty); }
set { SetValue(HeartRateProperty, value); }
}
// Using a DependencyProperty as the backing store for HeartRate. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HeartRateProperty =
DependencyProperty.Register("HeartRate", typeof(int), typeof(MainPage), new PropertyMetadata(0));
The TextBlock
text is then bound to HeartRate
. 然后将TextBlock
文本绑定到HeartRate
。 However, I keep getting this error when trying to set HeartRate
: 但是,在尝试设置HeartRate
时,我不断收到此错误:
The application called an interface that was marshalled for a different thread. 该应用程序调用了一个为不同线程编组的接口。 (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)) (来自HRESULT的异常:0x8001010E(RPC_E_WRONG_THREAD))
My guess is that it's trying to set HeartRate
while it is still being set from the call before. 我的猜测是它正在尝试设置HeartRate
而之前仍然是通过呼叫设置的。
Try to implement this and see how it goes, if you still want your int variable, then convert it back to string when displaying it in a text-block. 尝试实现它并看看它是如何进行的,如果你仍然想要你的int变量,那么在文本块中显示它时将其转换回字符串。
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
Textblock.Text = e.SensorReading.HeartRate.ToString())
}).AsTask();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.