maix.comm

maix.comm module

You can use maix.comm to access this module with MaixPy
This module is generated from MaixPy and MaixCDK

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

__init__

def __init__(self, buff_size: int = 1024, header: int = 3148663466, method_none_raise: bool = False) -> None

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

def get_msg(self, timeout: int = 0) -> ...

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

def resp_ok(self, cmd: int, body: maix.Bytes(bytes) = None) -> maix.err.Err

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

def report(self, cmd: int, body: maix.Bytes(bytes) = None) -> maix.err.Err

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

def resp_err(self, cmd: int, code: maix.err.Err, msg: str) -> maix.err.Err

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

def valid(self) -> bool

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

def set_method(method: str) -> maix.err.Err

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

def get_method() -> str

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()