stephane / modbusino

Small Modbus slave, RTU (serial) for Arduino
http://libmodbus.org
ISC License
143 stars 94 forks source link

Flush function #18

Open jeuhmeuh opened 4 years ago

jeuhmeuh commented 4 years ago

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.