简体   繁体   English

仅当值更新时(MacOS上为python),如何重复从BLE设备读取值?

[英]How to repeat reading the value from the BLE device only when the value updated (python on MacOS)?

As title, now I can get values from the BLE device, as the following codes shown: 作为标题,现在我可以从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()

And I can read the value from my BLE device only one time... Actually, the BLE device can continuously update the value when someone touch, so I like to know how should I do to achieve this? 而且我只能一次从BLE设备读取值...实际上,当有人触摸时BLE设备可以连续更新值,所以我想知道应该怎么做才能做到这一点? Thanks. 谢谢。

I would recommend to use the Observer Pattern. 我建议使用观察者模式。 An Example can be found here . 一个例子可以在这里找到。 In your case a BLE device would be a 'Subject' and notifies each time, when the value changes. 在您的情况下,BLE设备将是“主题”,并在值更改时每次通知一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何存储值并在python中更新时更改它? - How to store a value and change it when it is updated in python? Python:使用bleak模块时如何连接BLE设备 - Python: How to connect BLE device when i use bleak module 如何在python中使用pygatt从BLE设备获取通知? - How to get notifications from BLE Device using pygatt in python? 从csv读取时仅在第一个值中无法解释的前导空间 - Unexplainable leading space only in first value when reading from csv 无法使用 python 从 BLE 设备读取特定特性 - Unable to Readspecific characteristic from BLE Device with python 仅更新一个索引时,Python numpy zeros数组将为每个值分配1 - Python numpy zeros array being assigned 1 for every value when only one index is updated 有没有办法设置 python 套接字,以便服务器仅在客户端要求更新值时发送? - Is there a way to set up a python socket so that the server only sends when the client asks for an updated value? 如何在 Python 中重复具有不同变量值的过程 - How to repeat a process with different value of variable in Python 如何根据Python中的列值重复行 - How to repeat rows based on value of a column in Python Python变量分配:分配新值时更新先前的值 - Python variable assignment: previous value updated when new value assigned
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM