Serial Port Programming Part 5 - tcflush - TCIFLUSH,TCOFLUSH example
tcflush flushes/discards
- data which is written but not transmitted and/or
- data which is received but not read by user
The exact operation depends on the 'queue_selector' argument .
#include <termios.h>
int tcflush(int fildes, int queue_selector);
Possible values of queue_selector are:
TCIFLUSH - Flushes/Discards received data, but not read
TCOFLUSH - Flushes/Discards written data, but not transmitted
TCIOFLUSH - Flushes/Discards both
Let's write a sample code to check what happens when we
1. Loop until there are bytes in input buffer using 'FIONREAD' ioctl
2. Call tcflush with queue selector 'TCIFLUSH'
3. Check how many bytes are present in input buffer with 'FIONREAD' ioctl
Need two USB to serial/serial devices connected (TX-RX/RX-TX)
Code:
Output:
Comments
Post a Comment