[英]How to repeat reading the value from the BLE device only when the value updated (python on MacOS)?
作为标题,现在我可以从BLE设备获取值,如以下代码所示:
class RobotDelegate(object):
...
def peripheral_didDiscoverCharacteristicsForService_error_(self, peripheral, service, error):
for characteristic in self.service.characteristics():
if characteristic.UUID() == blebee_characteristic:
self.characteristic = characteristic
print ("self.characteristic.value = ", self.characteristic.value())
...
delegate = RobotDelegate()
manager = CBCentralManager.alloc()
manager.initWithDelegate_queue_options_(delegate, None, None)
AppHelper.runConsoleEventLoop()
而且我只能一次从BLE设备读取值...实际上,当有人触摸时BLE设备可以连续更新值,所以我想知道应该怎么做才能做到这一点? 谢谢。
我建议使用观察者模式。 一个例子可以在这里找到。 在您的情况下,BLE设备将是“主题”,并在值更改时每次通知一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.