maix.peripheral.uart
maix uart peripheral driver
You can use
maix.peripheral.uart
to access this module with MaixPy
This module is generated from MaixCDK
Module
No module
Enum
PARITY
item | doc |
---|---|
brief | uart parity enum |
values | PARITY_NONE: no parity PARITY_ODD: odd parity PARITY_EVEN: even parity PARITY_MAX: |
C++ defination code:
enum PARITY
{
PARITY_NONE = 0x00, // no parity
PARITY_ODD = 0x01, // odd parity
PARITY_EVEN = 0x02, // even parity
PARITY_MAX
}
STOP
item | doc |
---|---|
brief | uart stop bits |
values | STOP_1: 1 stop bit STOP_2: 2 stop bits STOP_1_5: 1.5 stop bits STOP_MAX: |
C++ defination code:
enum STOP
{
STOP_1 = 0x01, // 1 stop bit
STOP_2 = 0x02, // 2 stop bits
STOP_1_5 = 0x03, // 1.5 stop bits
STOP_MAX
}
BITS
item | doc |
---|---|
brief | uart stop bits |
values | BITS_5: 5 data bits BITS_6: 6 data bits BITS_7: 7 data bits BITS_8: 8 data bits BITS_MAX: |
C++ defination code:
enum BITS
{
BITS_5 = 5, // 5 data bits
BITS_6 = 6, // 6 data bits
BITS_7 = 7, // 7 data bits
BITS_8 = 8, // 8 data bits
BITS_MAX
}
FLOW_CTRL
item | doc |
---|---|
brief | uart flow control |
values | FLOW_CTRL_NONE: no flow control FLOW_CTRL_HW: hardware flow control FLOW_CTRL_MAX: |
C++ defination code:
enum FLOW_CTRL
{
FLOW_CTRL_NONE = 0, // no flow control
FLOW_CTRL_HW = 1, // hardware flow control
FLOW_CTRL_MAX
}
Variable
Function
list_devices
item | doc |
---|---|
brief | Get supported uart ports. |
return | uart ports list, string type. |
C++ defination code:
std::vector<std::string> list_devices()
Class
UART
item | doc |
---|---|
brief | maix uart peripheral driver |
C++ defination code:
class UART : public comm::CommBase
__init__
def __init__(self, port: str = '', baudrate: int = 115200, databits: BITS = ..., parity: PARITY = ..., stopbits: STOP = ..., flow_ctrl: FLOW_CTRL = ...) -> None
item | doc |
---|---|
type | func |
brief | UART constructor. You need to call open() to open the device. |
param | port: uart port. string type, can get it by uart.list_devices(). If empty, will not open device in constructor, default empty. if not empty, will auto open device in constructor, open fail will throw err.Exception. baudrate: baudrate of uart. int type, default 115200. databits: databits, values @see uart.DATA_BITS parity: parity, values @see uart.PARITY stopbits: stopbits, values @see uart.STOP_BITS flow_control: flow_control, values @see uart.FLOW_CTRL |
static | False |
C++ defination code:
UART(const std::string &port = "", int baudrate = 115200, uart::BITS databits = uart::BITS_8,
uart::PARITY parity = uart::PARITY_NONE, uart::STOP stopbits = uart::STOP_1,
uart::FLOW_CTRL flow_ctrl = uart::FLOW_CTRL_NONE)
set_port
def set_port(self, port: str) -> maix.err.Err
item | doc |
---|---|
type | func |
brief | Set port |
param | port: uart port. string type, can get it by uart.list_devices(). |
return | set port error code, err.Err type. |
static | False |
C++ defination code:
err::Err set_port(const std::string &port)
get_port
def get_port(self) -> str
item | doc |
---|---|
type | func |
brief | Get port |
return | uart port, string type. |
static | False |
C++ defination code:
std::string get_port()
set_baudrate
def set_baudrate(self, baudrate: int) -> maix.err.Err
item | doc |
---|---|
type | func |
brief | Set baud rate |
param | baudrate: baudrate of uart. int type, default 115200. |
return | set baud rate error code, err.Err type. |
static | False |
C++ defination code:
err::Err set_baudrate(int baudrate)
get_baudrate
def get_baudrate(self) -> int
item | doc |
---|---|
type | func |
brief | Get baud rate |
return | baud rate, int type. |
static | False |
C++ defination code:
int get_baudrate()
open
def open(self) -> maix.err.Err
item | doc |
---|---|
type | func |
brief | Open uart device, before open, port must be set in constructor or by set_port().\nIf already opened, do nothing and return err.ERR_NONE. |
return | open device error code, err.Err type. |
static | False |
C++ defination code:
err::Err open()
is_open
def is_open(self) -> bool
item | doc |
---|---|
type | func |
brief | Check if device is opened. |
return | true if opened, false if not opened. |
static | False |
C++ defination code:
bool is_open()
close
def close(self) -> maix.err.Err
item | doc |
---|---|
type | func |
brief | Close uart device, if already closed, do nothing and return err.ERR_NONE. |
return | close device error code, err.Err type. |
static | False |
C++ defination code:
err::Err close()
write_str
def write_str(self, str: str) -> int
item | doc |
---|---|
type | func |
brief | Send string data |
param | str: string data |
return | sent data length, < 0 means error, value is -err.Err. |
static | False |
C++ defination code:
int write_str(const std::string &str)
write
def write(self, data: maix.Bytes(bytes)) -> int
item | doc |
---|---|
type | func |
brief | Send data to uart |
param | data: direction [in], data to send, bytes type. If you want to send str type, use str.encode() to convert. |
return | sent length, int type, if < 0 means error, value is -err.Err. |
static | False |
C++ defination code:
int write(Bytes &data)
available
def available(self, timeout: int = 0) -> int
item | doc |
---|---|
type | func |
brief | Check if data available or wait data available. |
param | timeout: unit ms, timeout to wait data, default 0. 0 means check data available and return immediately, > 0 means wait until data available or timeout. - 1 means wait until data available. |
return | available data number, 0 if timeout or no data, <0 if error, value is -err.Err, can be err::ERR_IO, err::ERR_CANCEL, err::ERR_NOT_OPEN. |
throw | err.Exception if fatal error. |
static | False |
C++ defination code:
int available(int timeout = 0)
read
def read(*args, **kwargs)
item | doc |
---|---|
type | func |
brief | Recv data from uart |
param | len: max data length want to receive, default -1. -1 means read data in uart receive buffer. >0 means read len data want to receive. other values is invalid. timeout: unit ms, timeout to receive data, default 0. 0 means read data in uart receive buffer and return immediately, -1 means block until read len data, >0 means block until read len data or timeout. |
return | received data, bytes type. Attention, you need to delete the returned object yourself in C++. |
static | False |
C++ defination code:
Bytes *read(int len = -1, int timeout = 0)
readline
def readline(*args, **kwargs)
item | doc |
---|---|
type | func |
brief | Read line from uart, that is read until '\n' or '\r\n'. |
param | timeout: unit ms, timeout to receive data, default -1 means block until read '\n' or '\r\n'. > 0 means block until read '\n' or '\r\n' or timeout. |
return | received data, bytes type. If timeout will return the current received data despite not read '\n' or '\r\n'. e.g. If we want to read b'123\n', but when we only read b'12', timeout, then return b'12'. |
static | False |
C++ defination code:
Bytes *readline(int timeout = -1)