tcflush() not flushing serial port
Is there a trick to getting the tcflush() function to work on a serial port?
I've got 2 systems, one XP and one Fedora 9 connected via their serial ports. On each is a small test program to open the serial port, and if a button is pressed to send a test message: "hello World". Or if data is incoming, to read the data.
I start the program on XP, open the port, then send the test message twice, which transmits the data to the Fedora box.
Only then do I start the test program on the Fedora box. The beginning code
for the openning logic is:
port_ = ::open(portname, O_RDWR|O_NOCTTY|O_NONBLOCK|O_NDELAY);
rc = tcflush(port_, TCIOFLUSH);
My expectation was that the 2 messages which were sent BEFORE the port on the Linux box was opened, would be thrown away. But that doesn't happen. The test program on the Linux box reads all the data from the 2 messages right after it's open logic completes.
If anyone can suggest how to actually flush the port of this "spurious" data I would enjoy hearing about it.