Go Down

Topic: Arduino 1.0 beta Serial.flush() ?? (Read 2 times) previous topic - next topic

fat16lib

What will Serial.flush() do in the release version of 1.0?

The old Serial.flush() did this:
Quote
Flushes the buffer of incoming serial data. That is, any call to Serial.read() or Serial.available() will return only data received after all the most recent call to Serial.flush().


Serial.flush() in 1.0 beta waits for the output buffer to be empty.
Code: [Select]
void HardwareSerial::flush()
{
  while (_tx_buffer->head != _tx_buffer->tail)
    ;
}


What is the replacement for the old flush()?



Graynomad

That seems pretty strange, how would it ever return if no chars are received? And if chars are received you'd have to wait for the buffer to fill.

That can't be right.

The old flush did this

_rx_buffer->head = _rx_buffer->tail;

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

fat16lib

Serial now has a output buffer and is interrupt driven.  flush() now waits for the output buffer to empty.

Needless to say this was a surprise since flush() previously set the input buffer empty.

Hope 1.0 doesn't have too many more like this.

It certainly is a challenge to make a library work with both 0022 and 1.0 beta. 

Graynomad

Quote
flush() now waits for the output buffer to empty.

That's ludicrous, interrupts or no interrupts something called "flush" should do just that, and I see no reason it shouldn't.

I can see a good reason for a function that waits until the buffer is empty, but it should not be called "flush" especially when it overloads an old function with the same name but totally different functionality.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

retrolefty

I'm still waiting to see an application where using a flush() is a useful and proper operation. I have seen it misused a lot, one beginner around here was doing a flush() before each and every character read he performed. It's seems to be one of those functions that sounds powerful and useful, but so often misapplied and misunderstood.

And if I did every find a use for flush(), I would want it to either wait for the transmitting buffer to complete sending any characters I had sent out before flushing anything. While I have difficulty seeing the usefulness of flushing the receive buffer, I can't ever imagine wanting to flush output characters that I had sent before they actually leave the chip.  ;)

Go Up