5

I'm talking to a virtual serial port (an FTDI chip) using Boost's asio::serial_port library. I'd like to use hardware flow control (i.e. RTS/CTS), but I can't seem to find much documentation on how to use it with Boost. The code I've got is:

serialPort.set_option(boost::asio::serial_port::
flow_control(boost::asio::serial_port::flow_control::hardware));

With this line in place, the program will not run. It says:

libc++abi.dylib: terminate called throwing an exception
Abort trap: 6

If I change the ...flow_control::hardware to ...flow_control::software or ...flow_control::none, the serial port works fine (but without hardware flow control, obviously). I've spent a good bit of time looking for any documentation on this, but haven't found any. Does anyone know how to use flow control with Boost, or know where this is documented? I'm using Boost from Fink on Mac OS 10.8.2. Thanks!

1 Answers1

0

This is an old link, but considering it was the top search item on google for two different searches for serial data, I felt it needed an answer.

The line itself isn't the issue. Probably the issue is a thrown exception, due to calling the function at the wrong time.

Believe it or not, you need to open the port first and then set the flow control. The lines above do not give a full picture of when the lines are called in relation to other lines. Place the setoption to after when the port is open, and it should work.

There is also a version of set_option that takes a boost::system_error as a parameter. That version will return an error if it doesn't work for whatever reason. If you do not use the version with the system_error parameter, then you should be wrapping a function that can and will throw exceptions in a try/catch block.

Also, terminate is due to an unhandled exception (a coding issue), therefore the cryptic exception at terminate. If you handle the exception, the exception itself will point at the serial configuration issue (a runtime issue), which could be lack of permission to set it or the port not open so validation of RTS availability failed, etc.

Brian Lloyd
  • 173
  • 7