Serial Programming
Jump to navigation
Jump to search
References
- Serial Programming HOWTO
- Serial Programming Guide for POSIX Operating System
- Serial Port Programming in Windows and Linux
How-To
Flush Serial Buffers
Use constant TCSAFLUSH
for function tcsetattr
(see [1] and [2]):
Constant | Description |
---|---|
TCSANOW | Make changes now without waiting for data to complete |
TCSADRAIN | Wait until everything has been transmitted |
TCSAFLUSH | Flush input and output buffers and make the change |
This can be done even on a serial port that is already configured:
struct termios options;
tcgetattr(fd, &options); // Get current configuration of this port
cfsetispeed(&options, B115200); // Configure some port options (e.g. baud rate...)
...
tcsetattr(fd, TCSANOW, &options); // Apply the new settings immediately
... // Read / Write to the port...
tcsetattr(fd, TCSAFLUSH, &options); // Flush IO buffer