Bill Somerville
I think you should simplify your close semantics, passing an error code to your do_close() method is making it do more work than necessary.
I am an absolute beginner with asio. I read through the docs and the examples, but obviously missed some points. The example I presented is stolen from the web from http://www.nabble.com/Simple-serial-port-demonstration-with-boost-asio- asynchronous-I-O-td19849520.html
I don't understand the recreation of the serial_port object although I have not used the serial_port functionality myself. Also the close() method posts a do_close() call with a default constructed error object which is not handled correctly.
In my GUI application I have 2 buttons: connect/disconnect. I simply want them to work and I probably want to switch ports during runtime. So here is my nitty-gritty task: Write a class with the following interface class SerialLineCommunicator { public: Connect (std::string const & PortName); Disconnect(); WriteToSerialPort(std::string const & Text); }; This class should write all received characters to std::cout. The problem I have is: The Disconnect() method seems to have some problems which I was trying to track down, but I got lost. Neither a close() nor a delete of thread or communicator resolves the issue. I found that the demo code I had stolen from the internet obviously has the same problem if adopted such that it terminates the connection and then retakes it. I have not found any other working demo code and the docs are not helpful to me either.
I'm not sure why you need to use a loop in the main routine, if you want a server then use pending async calls to keep the io_service alive, if you want a client then perhaps errors should simply cause graceful termination.
Can you probably provide some code that *should* work? I have no idea anymore. Thanks, Markus