1#ifndef MSTL_CORE_SYSTEM_DEVICE_SERIAL_PORT_HPP__
2#define MSTL_CORE_SYSTEM_DEVICE_SERIAL_PORT_HPP__
6class MSTL_API serial_port final :
public device {
13 bool flow_control =
false;
14 bool xon_xoff =
false;
15 bool break_enable =
false;
16 bool dsr_sensitivity =
false;
17 bool dtr_control =
true;
18 bool rts_control =
true;
26 explicit serial_config(
uint32_t baud_rate = 115200)
27 : baud_rate(baud_rate) {}
38 bool framing_error{
false};
39 bool parity_error{
false};
40 bool overrun_error{
false};
41 bool break_detected{
false};
44 explicit serial_port(
const string& port_name,
45 const serial_config& config = serial_config{},
46 DEVICE_OPEN_FLAG flags = DEVICE_OPEN_FLAG::NONE);
48 void configure(
const serial_config& config);
49 serial_config get_configuration()
const;
51 void set_rts(
bool state);
52 void set_dtr(
bool state);
57 modem_status get_modem_status()
const;
59 void set_break(
bool enable);
60 line_status get_line_status()
const;
62 void purge_rx_buffer();
63 void purge_tx_buffer();
64 void purge_both_buffers();
66 size_t get_rx_queue_size()
const;
67 size_t get_tx_queue_size()
const;
70 serial_config current_config_{};
72#ifdef MSTL_PLATFORM_WINDOWS__
73 void configure_windows(
const serial_config& config);
74 modem_status get_modem_status_windows()
const;
76 void configure_linux(
const serial_config& config);
77 modem_status get_modem_status_linux()
const;
78 line_status get_line_status_linux()
const;
constexpr bool parity(const uintptr_t x) noexcept
计算整数的奇偶性
unsigned char uint8_t
8位无符号整数类型
unsigned int uint32_t
32位无符号整数类型
duration< int64_t, milli > milliseconds
毫秒持续时间
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL