簡體   English   中英

僅當值更新時(MacOS上為python),如何重復從BLE設備讀取值?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM