串行接口通信库
更多...
#include <rmvl/core/serial.hpp>
|
| | SerialPort (const std::string &device={}, int baud_rate=B115200) |
| | 构造新 SerialPort 对象,并自动打开
|
| |
| | ~SerialPort () |
| | 析构串口对象
|
| |
| void | open () |
| | 打开指定串口,或自动搜索所有可用的设备,并尝试打开第一个
|
| |
| void | close () |
| | 关闭串口
|
| |
| template<typename Tp > |
| bool | read (unsigned char head_flag, unsigned char tail_flag, Tp &data) |
| | 从串口读取数据到结构体
|
| |
| template<typename Tp > |
| bool | write (const Tp &data) |
| | 结构体数据写入串口
|
| |
| bool | isOpened () const |
| | 串口是否打开
|
| |
◆ SerialPort()
| rm::SerialPort::SerialPort |
( |
const std::string & | device = {}, |
|
|
int | baud_rate = B115200 ) |
|
inlineexplicit |
构造新 SerialPort 对象,并自动打开
- 参数
-
| [in] | device | 设备名,默认为空 |
| [in] | baud_rate | 波特率,默认为 B115200 |
◆ ~SerialPort()
| rm::SerialPort::~SerialPort |
( |
| ) |
|
|
inline |
◆ close()
| void rm::SerialPort::close |
( |
| ) |
|
◆ isOpened()
| bool rm::SerialPort::isOpened |
( |
| ) |
const |
|
inline |
◆ open()
| void rm::SerialPort::open |
( |
| ) |
|
打开指定串口,或自动搜索所有可用的设备,并尝试打开第一个
◆ read()
template<typename Tp >
| bool rm::SerialPort::read |
( |
unsigned char | head_flag, |
|
|
unsigned char | tail_flag, |
|
|
Tp & | data ) |
|
inline |
从串口读取数据到结构体
- 注解
- 每次读取后会清空缓冲区
- 模板参数
-
- 参数
-
| [in] | head_flag | 头帧 |
| [in] | tail_flag | 尾帧 |
| [out] | data | 读取的结构体数据 |
- 返回
- 是否读取成功
◆ write()
template<typename Tp >
| bool rm::SerialPort::write |
( |
const Tp & | data | ) |
|
|
inline |
结构体数据写入串口
- 注解
- 每次写入前会清空缓冲区
- 模板参数
-
- 参数
-
- 返回
- 是否写入成功
该类的文档由以下文件生成: