class BLEUARTServer
BLEUARTServer 类是一个 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 12label0 = None 13ble_periph = None 14 15 16data = None 17 18 19def setup(): 20 global label0, ble_periph, data 21 22 M5.begin() 23 Widgets.fillScreen(0x222222) 24 label0 = Widgets.Label("Text", 20, 31, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 25 26 ble_periph = BLEUARTServer(name="ble-uart") 27 28 29def loop(): 30 global label0, ble_periph, data 31 M5.update() 32 if (ble_periph.any()) > 0: 33 data = ble_periph.read() 34 label0.setText(str(data)) 35 ble_periph.write(data) 36 else: 37 time.sleep_ms(100) 38 39 40if __name__ == "__main__": 41 try: 42 setup() 43 while True: 44 loop() 45 except (Exception, KeyboardInterrupt) as e: 46 try: 47 from utility import print_error_msg 48 49 print_error_msg(e) 50 except ImportError: 51 print("please update to latest firmware")
UiFlow2 应用示例
cores3_bleuart_server_example.m5f2
Constructors
Methods
- BLEUARTServer.irq()
ble uart server 的 irq。
- BLEUARTServer.read(sz=None) bytes
从接收缓冲区读取数据。
- 参数:
sz (int) – 要读取的字节数。如果未指定,则读取所有数据。
- 返回:
从接收缓冲区读取的数据。
UIFLOW2




- BLEUARTServer.close()
关闭 BLE UART 服务器。
UIFLOW2

- BLEUARTServer.deinit()
反初始化 ble uart 服务器。
UIFLOW2









