maix.peripheral.uart
maix uart peripheral driver
You can use
maix.peripheral.uart
to access this module with MaixPy
This module is generated from MaixPy and MaixCDK
1. Module#
No module
2. Enum#
2.1. PARITY#
uart parity enum
item | describe |
---|---|
values | PARITY_NONE: no parity PARITY_ODD: odd parity PARITY_EVEN: even parity PARITY_MAX: |
C++ defination code:
2.2. 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:
2.3. 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:
2.4. 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:
3. Variable#
4. Function#
4.1. list_devices#
Get supported uart ports.
item | description |
---|---|
return | uart ports list, string type. |
C++ defination code:
5. Class#
5.1. UART#
maix uart peripheral driver
C++ defination code:
5.1.1. __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:
5.1.2. 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:
5.1.3. get_port#
Get port
item | description |
---|---|
type | func |
return | uart port, string type. |
static | False |
C++ defination code:
5.1.4. 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:
5.1.5. get_baudrate#
Get baud rate
item | description |
---|---|
type | func |
return | baud rate, int type. |
static | False |
C++ defination code:
5.1.6. 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:
5.1.7. is_open#
Check if device is opened.
item | description |
---|---|
type | func |
return | true if opened, false if not opened. |
static | False |
C++ defination code:
5.1.8. 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:
5.1.9. set_received_callback#
Set received callback function
item | description |
---|---|
type | func |
param | callback: function to call when received data |
static | False |
C++ defination code:
5.1.10. 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:
5.1.11. write#
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:
5.1.12. 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:
5.1.13. read#
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:
5.1.14. 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: