Flush function
jeuhmeuh opened this issue · comments
jeuhmeuh commented
Hello,
Since the newer version of Arduino IDE It appears that the Serial.flush method doesn't clear the rx buffer but the TX Buffer:
"Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)"
(Source arduino.cc )
I use the following function with success :
static void flush(void)
{
int i = 0;//Wait 3 Char lenght after last incomming byte
while (i <= _MODBUS_3_C_TIMEOUT) {
if (Serial.available()) {
Serial.read();
i = 0;
}
else {
i++;
}
delayMicroseconds(1);
}
}
thank you.