0

作为标题,现在我可以从 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设备可以不断更新值,所以我想知道我应该怎么做才能做到这一点?谢谢。

4

1 回答 1

0

我建议使用观察者模式。可以在这里找到一个示例。在您的情况下,BLE 设备将是“主题”,并在每次值更改时通知。

于 2018-12-05T09:14:51.353 回答