From a0a9d8388de1a8511884576a7f18a441a5e9b9cc Mon Sep 17 00:00:00 2001 From: dongyaosheng <842846344@qq.com> Date: Tue, 3 Feb 2026 11:27:05 +0800 Subject: [PATCH] serial_port add set_stop_bits/get_stop_bits --- include/boost/cobalt/io/serial_port.hpp | 5 +++++ src/io/serial_port.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/boost/cobalt/io/serial_port.hpp b/include/boost/cobalt/io/serial_port.hpp index 8fb43ed0..6895cc7a 100644 --- a/include/boost/cobalt/io/serial_port.hpp +++ b/include/boost/cobalt/io/serial_port.hpp @@ -46,6 +46,11 @@ struct BOOST_SYMBOL_VISIBLE serial_port final : stream [[nodiscard]] BOOST_COBALT_IO_DECL system::result set_parity(parity rate); [[nodiscard]] BOOST_COBALT_IO_DECL system::result get_parity(); + using stop_bits = asio::serial_port_base::stop_bits::type; + + [[nodiscard]] BOOST_COBALT_IO_DECL system::result set_stop_bits(stop_bits stop_bits); + [[nodiscard]] BOOST_COBALT_IO_DECL system::result get_stop_bits(); + using native_handle_type = typename asio::basic_serial_port::native_handle_type; native_handle_type native_handle() {return serial_port_.native_handle();} diff --git a/src/io/serial_port.cpp b/src/io/serial_port.cpp index c45b1ebf..bb1c2bc9 100644 --- a/src/io/serial_port.cpp +++ b/src/io/serial_port.cpp @@ -95,6 +95,21 @@ auto serial_port::get_parity() -> system::result return ec ? ec : system::result(br.value()); } +system::result serial_port::set_stop_bits(stop_bits stop_bits) +{ + system::error_code ec; + serial_port_.set_option(asio::serial_port_base::stop_bits(stop_bits), ec); + return ec ? ec : boost::system::result(); +} + +auto serial_port::get_stop_bits() -> system::result +{ + system::error_code ec; + asio::serial_port_base::stop_bits sb; + serial_port_.get_option(sb, ec); + return ec ? ec : boost::system::result(sb.value()); +} + serial_port::serial_port(const cobalt::executor & executor) : serial_port_(executor) {} serial_port::serial_port(std::string_view device, const cobalt::executor & executor)