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 应用示例

example.png

cores3_bleuart_server_example.m5f2

Constructors

class bleuart.BLEUARTServer(name='', rxbuf=100, verbose=False)

创建一个 BLE UART 服务器。

参数:
  • name (str) – BLE 设备的名称。

  • rxbuf (int) – 接收缓冲区的大小。

  • verbose (bool) – 启用详细输出。

UIFLOW2

init.png

Methods

BLEUARTServer.irq()

ble uart server 的 irq。

BLEUARTServer.any() int

检查接收缓冲区中是否有数据。

返回:

接收缓冲区中的字节数。

UIFLOW2

any.png

BLEUARTServer.read(sz=None) bytes

从接收缓冲区读取数据。

参数:

sz (int) – 要读取的字节数。如果未指定,则读取所有数据。

返回:

从接收缓冲区读取的数据。

UIFLOW2

read_all.png

read_bytes.png

read_raw_data.png

readline.png

BLEUARTServer.write(data: bytes)

向 ble uart server 写入数据。

参数:

data (bytes) – 要写入的数据。

UIFLOW2

write.png

write1.png

write_line.png

write_list.png

write_raw_data.png

write_raw_data1.png

BLEUARTServer.close()

关闭 BLE UART 服务器。

UIFLOW2

close.png

BLEUARTServer.deinit()

反初始化 ble uart 服务器。

UIFLOW2

deinit.png