Boost Asio serial_port - need help with io

前端 未结 3 1920
太阳男子
太阳男子 2020-12-14 19:38

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

相关标签:
3条回答
  • 2020-12-14 20:20

    Thanks to the help from here and other places I got it working. Wrote a small program that might help some people figure out the boost serial port stuff as well.

    boostserialportdemo.cpp

    0 讨论(0)
  • 2020-12-14 20:30

    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));
    

    The libraries acceptance of buffer types is very flexible and you may want to read further on that topic here: Buffers.

    0 讨论(0)
  • 2020-12-14 20:32

    If you are wondering why his example gives a compile error, change CSIZE to C_SIZE on both lines. This is probably the only good example program on the web.
    Thanks.

    0 讨论(0)
提交回复
热议问题