@john-lee
2021-01-03T13:29:04.000000Z
字数 776
阅读 622
Boost.Asio
Boost.Asio 包括用于以可移植方式创建和操作串行端口的类。例如,可以使用以下方法打开串行端口:
serial_port port(my_io_context, name);
其中 name 在 Windows 上类似于"COM1"
,在 POSIX 平台上类似于"/dev/ttyS0"
。
一旦打开,串行端口就可以用作流。这意味着这些对象可以与任何read()
、async_read()
、write()
、async_write()
、read_until()
或async_read_until()
自由函数一起使用。
串行端口实现还包括用于配置端口波特率、流控制类型、奇偶校验、停止位和字符大小的选项类。
serial_port, serial_port_base, serial_port_base::baud_rate, serial_port_base::flow_control, serial_port_base::parity, serial_port_base::stop_bits, serial_port_base::character_size。
所有 POSIX 平台都提供串行端口。对于 Windows,只有在使用 I/O 完成端口后端时(这是默认值),串行端口才在编译时可用。一个程序可以测试宏BOOST_ASIO_HAS_SERIAL_PORT
以确定它们是否受支持。
Copyright © 2003-2020 Christopher M. Kohlhoff
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)