How to empty the buffer for Serial port?
It's quite simple to empty the serial buffer - you just read all the data that is in the buffer and throw it away:

while (port-&gt;available()) {
    port-&gt;read();
}