升压短耳serial_port - 与IO需要帮助 [英] Boost Asio serial_port - need help with io
问题描述
所以我一直努力学习了boost :: ASIO的东西传达给使用RS232串行设备。该documementation是稀疏和实施例是不存在的。无法弄清楚究竟如何与设备进行通信。该设备无法发送数据,所以我需要做的就是写,但其他项目的实际需要来回沟通与那将是AP preciated所以帮助。什么code我到目前为止如下:
So I've been trying to learn the boost::asio stuff to communicate to a serial device using RS232. The documementation is sparse and the examples are non-existent. Can't figure out exactly how to communicate with the device. The device can't send data so all I need to do is write, but other projects require actual back and forth communication so help with that would be appreciated. What code I have so far follows.
#include <boost/asio/serial_port.hpp>
using namespace::boost::asio;
int main()
{
io_service io;
serial_port port( io, "COM3" );
port.set_option( serial_port_base::baud_rate( 19200 ) );
unsigned char commands[4] = { 1, 128, 240, 0 };
// write the commands to the device
return 0;
}
在短:必要与serial_port的IO部分帮助
In short: need help with the io part of the serial_port.
推荐答案
在除了波特率,你可能还需要设置其他选项,如:character_size,FLOW_CONTROL,奇偶校验和stop_bits。将数据写入到你可以做以下串行端口:
In addition to the baud rate, you may also need to set other options like: character_size, flow_control, parity and stop_bits. To write your data to the serial port you can do the following:
boost::asio::write(port, boost::asio::buffer(commands, 4));
该库接受缓冲区类型是非常灵活的,你可能想在该主题在这里进一步阅读:<一href=\"http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/overview/core/buffers.html\">Buffers.
这篇关于升压短耳serial_port - 与IO需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!