class BLEUARTClient
BLEUARTClient 类是一个 BLE UART 客户端,可以连接到 BLE UART 服务器并与其通信。
MicroPython 应用示例:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from bleuart import * 9import time 10 11 12ble_central = None 13 14 15nums = None 16i = None 17 18 19def setup(): 20 global ble_central, nums, i 21 22 M5.begin() 23 ble_central = BLEUARTClient() 24 ble_central.connect("ble-uart", timeout=2000) 25 while not (ble_central.is_connected()): 26 time.sleep_ms(100) 27 print("Connected") 28 nums = [4, 8, 15, 16, 23, 46] 29 i = 1 30 while True: 31 ble_central.write((str((nums[int(i - 1)])))) 32 i = (i + 1) % len(nums) 33 time.sleep(1) 34 print((str("rx:") + str(((ble_central.read()).decode())))) 35 ble_central.close() 36 ble_central.deinit() 37 38 39def loop(): 40 global ble_central, nums, i 41 M5.update() 42 43 44if __name__ == "__main__": 45 try: 46 setup() 47 while True: 48 loop() 49 except (Exception, KeyboardInterrupt) as e: 50 try: 51 from utility import print_error_msg 52 53 print_error_msg(e) 54 except ImportError: 55 print("please update to latest firmware")
UiFlow2 应用示例:
atoms3_bleuart_client_example.m5f2
Constructors
Methods
- BLEUARTClient.irq()
ble uart client 的 irq。
- BLEUARTClient.is_connected()
检查 ble uart server 是否已连接。
UIFLOW2:

- BLEUARTClient.connect(name, timeout=2000)
连接到 ble uart 服务器。
UIFLOW2:

- BLEUARTClient.read(sz=None) bytes
从接收缓冲区读取数据。
- 参数:
sz (int) – 要读取的字节数。如果未指定,则读取所有数据。
- 返回:
从接收缓冲区读取的数据。
UIFLOW2:




- BLEUARTClient.close()
关闭 ble uart 服务器。
UIFLOW2:

- BLEUARTClient.deinit()
反初始化 ble uart server。
UIFLOW2:









