0
在https://github.com/jrowberg/bglib/blob/master/Python/bglib.py處定義了一個事件API。但是因爲我是Python的新手,我無法理解如何使用它。如何使用此Python事件API
例如,我應該怎樣在我的代碼中聽取事件ble_rsp_system_hello
?
在BGAPIEvent
類中__get__
和__set__
方法的意義是什麼?
在https://github.com/jrowberg/bglib/blob/master/Python/bglib.py處定義了一個事件API。但是因爲我是Python的新手,我無法理解如何使用它。如何使用此Python事件API
例如,我應該怎樣在我的代碼中聽取事件ble_rsp_system_hello
?
在BGAPIEvent
類中__get__
和__set__
方法的意義是什麼?
找到並使用測試進行驗證。 以下是做到這一點的方法。
ble = bglib.BGLib()
ser = serial.Serial(port="/dev/ttyACM1", baudrate=115200, timeout=1)
ble.send_command(ser, ble.ble_cmd_gap_set_mode(0x82, 0x01)
def handler(sender, earg):
print earg['address']
ble.ble_rsp_system_address_get += handle
while (1):
# check for all incoming data (no timeout, non-blocking)
ble.check_activity(ser)
# don't burden the CPU
time.sleep(0.01)
更多信息,可以發現here,