Boost Asio Serial Port Flush
I'm having a peculiar problem with boost::asio and a boost::asio::serialport device. The code is finally working pretty well with asynchronous reads and stuff, but I can't figure out how to change the speed of the serial port on the fly.
I'm want to check for incoming data packages on the serial port, using boost.asio. Each data packet will start with a header that is one byte long, and will specify what type of the message has been sent.
What I'm trying to do right now is just telling the device connected in my serial port to change the serial port speed to say 38400 baud, then I'm setting my computers serial port to the same speed via: port.setoption(boost::asio::serialportbase::baudrate(rate)); But what's really happening is that if I do the setoption part, the device never receives the command to change the speed. If I don't do the setoption part the device changes speed correctly. From what I gather what's happening is that the (blocking, synchronous) write puts stuff in the hardware buffer on my computer and returns, then does the setoption which discards the buffer (before it has had time to send data to the device).
So I need to think of some way to check if the hardware buffer is empty and the device really has received the command to change the speed, before reconfiguring my computers serial port. I also cannot find any info on if I have to do close and open on the port for the speed change to take affect. I'm also wondering if close discards the stuff in the buffer or not. I'm using a USB-serial port adapter and my platform is Ubuntu 10.10 if it makes any difference.Problems Reply- Have you looked at man 3 termios? It seems tcdrain does what you need tcdrain waits until all output written to the object referred to by fd has been transmitted. You can get the native descriptor from the boost::asio::serialport::native method.
From your computer by using the Add/Remove Program feature in the Window's Control Panel. College algebra solved.
Did you try flushing the buffer or looking for an appropriate flush alternative? Are the client and server in the same process?
ASIO iostream flush not working? Category: Views: 0 Time:2010-12-16.