从 Microsoft Band 获取心率
Get Heart Rate From Microsoft Band
我正在尝试从 Microsoft Band 获取心率。只要值发生变化,它就应该更新。然后我试图在 TextBlock
中显示该值。我首先创建一个 IBandClient
的实例,然后像这样设置它的 HeartRate.ReadingChanged
方法:
bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
然后我尝试像这样更新值:
private void HeartRate_ReadingChanged(object sender, Microsoft.Band.Sensors.BandSensorReadingEventArgs<Microsoft.Band.Sensors.IBandHeartRateReading> e)
{
HeartRate = e.SensorReading.HeartRate;
}
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));
然后 TextBlock
文本绑定到 HeartRate
。但是,我在尝试设置 HeartRate
:
时不断收到此错误
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
我的猜测是它正在尝试设置 HeartRate
,而之前的调用仍在设置它。
尝试实现它,看看效果如何,如果您仍然需要 int 变量,则在文本块中显示它时将其转换回字符串。
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
Textblock.Text = e.SensorReading.HeartRate.ToString())
}).AsTask();
我正在尝试从 Microsoft Band 获取心率。只要值发生变化,它就应该更新。然后我试图在 TextBlock
中显示该值。我首先创建一个 IBandClient
的实例,然后像这样设置它的 HeartRate.ReadingChanged
方法:
bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
然后我尝试像这样更新值:
private void HeartRate_ReadingChanged(object sender, Microsoft.Band.Sensors.BandSensorReadingEventArgs<Microsoft.Band.Sensors.IBandHeartRateReading> e)
{
HeartRate = e.SensorReading.HeartRate;
}
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));
然后 TextBlock
文本绑定到 HeartRate
。但是,我在尝试设置 HeartRate
:
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
我的猜测是它正在尝试设置 HeartRate
,而之前的调用仍在设置它。
尝试实现它,看看效果如何,如果您仍然需要 int 变量,则在文本块中显示它时将其转换回字符串。
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
Textblock.Text = e.SensorReading.HeartRate.ToString())
}).AsTask();