Skip to content

Commit cecc81c

Browse files
dongyaoshengklemens-morgenstern
authored andcommitted
serial_port add set_stop_bits/get_stop_bits
1 parent 3e86aaa commit cecc81c

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

include/boost/cobalt/io/serial_port.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ struct BOOST_SYMBOL_VISIBLE serial_port final : stream
4646
[[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> set_parity(parity rate);
4747
[[nodiscard]] BOOST_COBALT_IO_DECL system::result<parity> get_parity();
4848

49+
using stop_bits = asio::serial_port_base::stop_bits::type;
50+
51+
[[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> set_stop_bits(stop_bits stop_bits);
52+
[[nodiscard]] BOOST_COBALT_IO_DECL system::result<stop_bits> get_stop_bits();
53+
4954
using native_handle_type = typename asio::basic_serial_port<executor>::native_handle_type;
5055
native_handle_type native_handle() {return serial_port_.native_handle();}
5156

src/io/serial_port.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ auto serial_port::get_parity() -> system::result<parity>
9595
return ec ? ec : system::result<parity>(br.value());
9696
}
9797

98+
system::result<void> serial_port::set_stop_bits(stop_bits stop_bits)
99+
{
100+
system::error_code ec;
101+
serial_port_.set_option(asio::serial_port_base::stop_bits(stop_bits), ec);
102+
return ec ? ec : boost::system::result<void>();
103+
}
104+
105+
auto serial_port::get_stop_bits() -> system::result<stop_bits>
106+
{
107+
system::error_code ec;
108+
asio::serial_port_base::stop_bits sb;
109+
serial_port_.get_option(sb, ec);
110+
return ec ? ec : boost::system::result<stop_bits>(sb.value());
111+
}
112+
98113
serial_port::serial_port(const cobalt::executor & executor)
99114
: serial_port_(executor) {}
100115
serial_port::serial_port(std::string_view device, const cobalt::executor & executor)

0 commit comments

Comments
 (0)