我正在构建一个Xamarin.Forms
跨平台移动应用,它使用Monkey.Robotics
来实现其Bluetoth Low Energy功能。我正在连接基于mbed
的{{3}}投诉。
在Xamarin C#中,是什么触发了Monkey.Robotics中的特征ValueUpdated
事件?
这是我的C#基于的标准示例:
if (characteristic.CanUpdate) {
characteristic.ValueUpdated += (s, e) => {
Debug.WriteLine("characteristic.ValueUpdated");
Device.BeginInvokeOnMainThread( () => {
UpdateDisplay(characteristic);
});
IsBusy = false; // only spin until the first result is received
};
IsBusy = true;
characteristic.StartUpdates();
}
这一直有效,但由于我改为自己连接的自定义GATT服务,因此永远不会触发ValueUpdated事件。这个事件是什么以及它是如何触发的?这是一个从特性中读取的属性,由mbed设备设置,还是移动端工作的东西?
由于
答案 0 :(得分:-1)
这是来自Android implementation
this._gattCallback.CharacteristicValueUpdated += (object sender, CharacteristicReadEventArgs e) => {
// it may be other characteristics, so we need to test
if(e.Characteristic.ID == this.ID) {
// update our underlying characteristic (this one will have a value)
//TODO: is this necessary? probably the underlying reference is the same.
//this._nativeCharacteristic = e.Characteristic;
this.ValueUpdated (this, e);
}
};