异步串行接口通信库,仅支持读写字符串
更多...
#include <rmvl/io/serial.hpp>
|
| | SerialPort (IOContext &io_context, std::string_view device, BaudRate baud_rate) |
| | 构造新串口对象
|
| SerialReadAwaiter | read () |
| | 异步读取串口数据
|
| template<typename Tp> |
| SerialPort & | operator>> (Tp &)=delete |
| SerialWriteAwaiter | write (std::string_view data) |
| | 异步写入串口数据
|
| template<typename Tp> |
| SerialPort & | operator<< (const Tp &)=delete |
| | SerialPort (std::string_view device, BaudRate baud_rate, SerialReadMode read_mode={}) |
| | 构造新串口对象
|
| template<typename Tp, typename Enable = std::enable_if_t<std::is_aggregate_v<Tp>>> |
| bool | read (uint8_t head_flag, uint8_t tail_flag, Tp &data) |
| | 从串口读取数据到聚合体中
|
| template<typename Tp, typename Enable = std::enable_if_t<std::is_aggregate_v<Tp>>> |
| bool | read (Tp &data) |
| | 不带头尾标志的数据读取,从串口读取数据到聚合体中
|
| bool | read (std::string &data) |
| | 不带头尾标志的数据读取,从串口读取字符串
|
| template<typename Tp, typename Enable = std::enable_if_t<std::is_aggregate_v<Tp> || std::is_same_v<Tp, std::string>>> |
| SerialPort & | operator>> (Tp &data) |
| template<typename Tp, typename Enable = std::enable_if_t<std::is_aggregate_v<Tp>>> |
| bool | write (const Tp &data) |
| | 数据写入串口
|
| bool | write (std::string_view data) |
| | 写入字符串到串口
|
| template<typename Tp, typename Enable = std::enable_if_t<std::is_aggregate_v<Tp> || std::is_same_v<Tp, std::string_view>>> |
| SerialPort & | operator<< (const Tp &data) |
| bool | isOpened () const |
| | 串口是否打开
|
◆ SerialPort()
| rm::async::SerialPort::SerialPort |
( |
IOContext & | io_context, |
|
|
std::string_view | device, |
|
|
BaudRate | baud_rate ) |
构造新串口对象
- 参数
-
| [in] | io_context | 异步 I/O 执行上下文 |
| [in] | device | 设备名 |
| [in] | baud_rate | 波特率 |
◆ operator<<()
template<typename Tp>
| SerialPort & rm::async::SerialPort::operator<< |
( |
const Tp & | | ) |
|
|
delete |
◆ operator>>()
template<typename Tp>
| SerialPort & rm::async::SerialPort::operator>> |
( |
Tp & | | ) |
|
|
delete |
◆ read()
异步读取串口数据
std::string
str =
co_await serial.read();
- 返回
- 读取到的字符串数据
◆ write()
异步写入串口数据
- 参数
-
- 返回
- 是否写入成功
bool success = co_await serial.write("12345");
该类的文档由以下文件生成: