Sleep for 1s before calling tcflush

The serial port was not flushed after opening. The fix is to sleep for 1s between open and calling tcflush.