maix::comm
maix.comm module
This is
maix::comm
module of MaixCDK.
All of these elements are in namespacemaix::comm
.For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!
Module
module | brief |
---|---|
modbus | maix.comm.modbus module |
Enum
Variable
Function
add_default_comm_listener
Add default CommProtocol listener.\nWhen the application uses this port, the listening thread will immediately\nrelease the port resources and exit. If you need to start the default listening thread again,\nplease release the default port resources and then call this function.
C++ defination code:
void add_default_comm_listener()
rm_default_comm_listener
Remove default CommProtocol listener.
item | description |
---|---|
return | bool type. |
C++ defination code:
bool rm_default_comm_listener()
Class
CommProtocol
Class for communication protocol
C++ defination code:
class CommProtocol
CommProtocol
Construct a new CommProtocol object
item | description |
---|---|
type | func |
param | buff_size: buffer size, default to 1024 bytes header: Customize header, default is maix.protocol.HEADER method_none_raise: If method set to "none", raise err.Exception() if method_none_raise is true. Default false, if method is "none" and this arg is false, valid() function will return false and get_msg() always return none. |
throw | Initialize failed will raise err::Exception() |
static | False |
C++ defination code:
CommProtocol(int buff_size = 1024, uint32_t header=maix::protocol::HEADER, bool method_none_raise = false)
get_msg
Read data to buffer, and try to decode it as maix.protocol.MSG object
item | description |
---|---|
type | func |
param | timeout: unit ms, 0 means return immediatly, -1 means block util have msg, >0 means block until have msg or timeout. |
return | decoded data, if nullptr, means no valid frame found. Attentioin, delete it after use in C++. |
static | False |
C++ defination code:
protocol::MSG *get_msg(int timeout = 0)
resp_ok
Send response ok(success) message
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length cmd: CMD value body: response body, can be null body_len: response body length, can be 0 |
return | send response error code, maix.err.Err type |
static | False |
C++ defination code:
err::Err resp_ok(uint8_t *buff, int buff_len, uint8_t cmd, uint8_t *body = nullptr, int body_len = 0)
resp_ok (overload 1)
Send response ok(success) message
item | description |
---|---|
type | func |
param | cmd: CMD value body: response body, can be null body_len: response body length, can be 0 |
return | encoded data, if nullptr, means error, and the error code is -err.Err. Attentioin, delete it after use in C++. |
static | False |
C++ defination code:
err::Err resp_ok(uint8_t cmd, uint8_t *body = nullptr, int body_len = 0)
resp_ok (overload 2)
Send response ok(success) message
item | description |
---|---|
type | func |
param | cmd: CMD value body: response body, can be null |
return | encoded data, if nullptr, means error, and the error code is -err.Err. Attentioin, delete it after use in C++. |
static | False |
C++ defination code:
err::Err resp_ok(uint8_t cmd, Bytes *body = nullptr)
report
Send report message
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length cmd: CMD value body: report body, can be null body_len: report body length, can be 0 |
return | send report error code, maix.err.Err type |
static | False |
C++ defination code:
err::Err report(uint8_t *buff, int buff_len, uint8_t cmd, uint8_t *body = nullptr, int body_len = 0)
report (overload 1)
Send report message
item | description |
---|---|
type | func |
param | cmd: CMD value body: report body, can be null body_len: report body length, can be 0 |
return | encoded data, if nullptr, means error, and the error code is -err.Err. Attentioin, delete it after use in C++. |
static | False |
C++ defination code:
err::Err report(uint8_t cmd, uint8_t *body = nullptr, int body_len = 0)
report (overload 2)
Send report message
item | description |
---|---|
type | func |
param | cmd: CMD value body: report body, can be null |
return | encoded data, if nullptr, means error, and the error code is -err.Err. Attentioin, delete it after use in C++. |
static | False |
C++ defination code:
err::Err report(uint8_t cmd, Bytes *body = nullptr)
resp_err
Encode response error message to buffer
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length cmd: CMD value code: error code msg: error message |
return | send response error code, maix.err.Err type |
static | False |
C++ defination code:
err::Err resp_err(uint8_t *buff, int buff_len, uint8_t cmd, err::Err code, const std::string &msg)
resp_err (overload 1)
Encode response error message to buffer
item | description |
---|---|
type | func |
param | cmd: CMD value code: error code msg: error message |
return | encoded data, if nullptr, means error, and the error code is -err.Err. Attentioin, delete it after use in C++. |
static | False |
C++ defination code:
err::Err resp_err(uint8_t cmd, err::Err code, const std::string &msg)
valid
Is CommProtocol valid, only not valid when method not set to "none".
item | description |
---|---|
type | func |
return | false if commprotocol method is "none". |
static | False |
C++ defination code:
bool valid()
set_method
Set CommProtocol method
item | description |
---|---|
type | func |
param | method: Can be "uart" or "none", "none" means not use CommProtocol. |
static | True |
C++ defination code:
static err::Err set_method(const std::string &method)
get_method
Get CommProtocol method
item | description |
---|---|
type | func |
return | method Can be "uart" or "none", "none" means not use CommProtocol. |
static | True |
C++ defination code:
static std::string get_method()
CommBase
Communication base class, all communication methods should implement this interface
C++ defination code:
class CommBase
open
Open device, if 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:
virtual err::Err open()
close
Close 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:
virtual err::Err close()
is_open
Check if opened
item | description |
---|---|
type | func |
return | true if opened, else false. |
static | False |
C++ defination code:
virtual bool is_open()
write
Send data to device
item | description |
---|---|
type | func |
param | buff: data buffer len: data length need to send, the len must <= buff length. |
return | sent data length, < 0 means error, value is -err.Err. |
static | False |
C++ defination code:
virtual int write(const uint8_t *buff, int len)
write (overload 1)
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:
virtual int write(Bytes &data)
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:
virtual int read(uint8_t *buff, int buff_len, int recv_len, int timeout)
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. |
static | False |
C++ defination code:
virtual Bytes *read(int len, int timeout)