maix::peripheral::uart
maix uart peripheral driver
This is
maix::peripheral::uart
module of MaixCDK.
All of these elements are in namespacemaix::peripheral::uart
.For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!
Module
No module
Enum
PARITY
uart parity enum
item | describe |
---|---|
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
uart stop bits
item | describe |
---|---|
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
uart stop bits
item | describe |
---|---|
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
uart flow control
item | describe |
---|---|
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
Get supported uart ports.
item | description |
---|---|
return | uart ports list, string type. |
C++ defination code:
std::vector<std::string> list_devices()
Class
UART
maix uart peripheral driver
C++ defination code:
class UART : public comm::CommBase
__init__
UART constructor. You need to call open() to open the device.
item | description |
---|---|
type | func |
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
Set port
item | description |
---|---|
type | func |
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
Get port
item | description |
---|---|
type | func |
return | uart port, string type. |
static | False |
C++ defination code:
std::string get_port()
set_baudrate
Set baud rate
item | description |
---|---|
type | func |
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
Get baud rate
item | description |
---|---|
type | func |
return | baud rate, int type. |
static | False |
C++ defination code:
int get_baudrate()
open
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.
item | description |
---|---|
type | func |
return | open device error code, err.Err type. |
static | False |
C++ defination code:
err::Err open()
is_open
Check if device is opened.
item | description |
---|---|
type | func |
return | true if opened, false if not opened. |
static | False |
C++ defination code:
bool is_open()
close
Close uart device, if already closed, do nothing and return err.ERR_NONE.
item | description |
---|---|
type | func |
return | close device error code, err.Err type. |
static | False |
C++ defination code:
err::Err close()
set_received_callback
Set received callback function
item | description |
---|---|
type | func |
param | callback: function to call when received data |
static | False |
C++ defination code:
void set_received_callback(std::function<void(uart::UART&, Bytes&)> callback)
write
Send data to device
item | description |
---|---|
type | func |
param | buff: data buffer len: data length need to send |
return | sent data length, < 0 means error, value is -err.Err. |
static | False |
C++ defination code:
int write(const uint8_t *buff, int len)
write (overload 1)
Send data to device
item | description |
---|---|
type | func |
param | buff: data buffer len: data length need to send, if len == -1, means buff is a string, send buff until '\0'. |
return | sent data length, < 0 means error, value is -err.Err. |
static | False |
C++ defination code:
int write(const char *buff, int len = -1)
write (overload 2)
Send string data
item | description |
---|---|
type | func |
param | str: string data |
return | sent data length, < 0 means error, value is -err.Err. |
static | False |
C++ defination code:
int write(const std::string &str)
write (overload 3)
Send data to uart
item | description |
---|---|
type | func |
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)
write_str
Send string data
item | description |
---|---|
type | func |
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)
available
Check if data available or wait data available.
item | description |
---|---|
type | func |
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
Receive data
item | description |
---|---|
type | func |
param | buff: data buffer to store received data buff_len: data buffer length recv_len: max data length want to receive, default -1. -1 means read data in uart receive buffer. >0 means read recv_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 recv_len data, >0 means block until read recv_len data or timeout. |
return | received data length, < 0 means error, value is -err.Err. |
static | False |
C++ defination code:
int read(uint8_t *buff, int buff_len, int recv_len = -1, int timeout = 0)
read (overload 1)
Recv data from uart
item | description |
---|---|
type | func |
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++. |
throw | Read failed will raise err.Exception error. |
static | False |
C++ defination code:
Bytes *read(int len = -1, int timeout = 0)
readline
Read line from uart, that is read until '\n' or '\r\n'.
item | description |
---|---|
type | func |
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)