The Tcflush function brushes (throws) the input cache (the terminal driver has taken over, but the user has not yet read it) or the output cache (the user has written but not yet sent).
int tcflush (int filedes,int quene)
The number of quene should be one of the following three constants:
*tciflush brushing the input queue
*tcoflush brush out the output queue
*tcioflush brushing input, output queue
For example: Tcflush (Fd,tciflush);
After opening the serial port, the serial port actually can begin to read the data, this period of time if the user does not read, will be saved in the buffer, if the user does not want to start a piece of data, or found that the buffer data is wrong, you can use this function to empty the buffer
Tcflush (fdcom, Tciflush);
Sleep (2);
Recvlen = Portrecv (fdcom, Recvbuf, ten, portinfo.baudrate);
In this way, the data sent before sleep is emptied.
buffers , also known as caches, are part of the memory space. In other words, a certain amount of storage space is reserved in the memory space, which is used to buffer the data in and out, which is called the buffer space.
The buffer is divided into input buffer and output buffer according to its corresponding input device and output device.
the role of buffers
The function of the buffer is to solve the problem of speed mismatch, high-speed CPU and memory, memory and hard disk, CPU and IO speed mismatch problem, and the inductive buffer, such as we read from the disk, we first put the read data in the buffer, the computer and then read the data directly from the buffer, When the buffer data read and then go to the disk to read, so that you can reduce the disk read and write times, and the computer to the buffer operation is much faster than the operation of the disk, so the application of buffer can greatly improve the speed of the computer.
A buffer is an area of memory that is used between input and the CPU to cache data. It enables low-speed input and high-speed CPUs to work in a coordinated effort to avoid low-speed input consuming CPUs. Frees up the CPU so it can work efficiently.
Type of buffer
There are three types of buffers: full-buffered, row-buffered, and unbuffered.
1. Full buffer
In this case, the actual I/O operation is not performed until the standard I/O cache is filled. A typical representation of a full buffer is the read and write of a disk file.
2, Row buffer
In this case, the real I/O operation is performed when a newline character is encountered in the input and output. At this point, we enter the word Mr. Foo stored in the buffer, and so on when the return hit enter the actual I/O operation. The typical representation is keyboard input data.
3, without buffering
Without buffering, which is not buffering, standard error stderr is a typical representation, which allows the error message to be displayed directly as soon as possible.
Transferred from: http://blog.csdn.net/a4150902/article/details/7584676
Serial Programming Tcflush () function (GO)