Automatically Flushing the Formatted I/O Buffers
Although you can explicitly flush the buffers by making a call to viFlush(), the buffers are flushed implicitly under some conditions. These conditions vary for the viPrintf() and viScanf() operations. In addition, you can modify the conditions through attributes.
The write buffer is maintained by the viPrintf(), viVPrintf(), viBufWrite(), and viVQueryf() (write side) operations. To explicitly flush the write buffer, you can make a call to the viFlush() operation with a write flag set.
The standard conditions for automatically flushing the buffer are as follows.
- Whenever the END indicator is sent. The indicator could be either the EOS character or the END bit/EOI line, depending on the current state of the attributes which select these modes.
- When the write buffer is full.
- In response to a call to viSetBuf() with the VI_WRITE_BUF flag set.
In addition to these rules, the VI_ATTR_WR_BUF_OPER_MODE attribute can modify the flushing of the buffer. The default setting for this attribute is VI_FLUSH_WHEN_FULL, which means that the preceding three rules apply. However, if the attribute is set to VI_FLUSH_ON_ACCESS, the buffer is flushed with every call to viPrintf() and viVPrintf(), essentially disabling the buffering mode.
The read buffer is maintained by the viScanf(), viVScanf(), viBufRead(), and viVQueryf() (read side) operations. To explicitly flush the read buffer, you can make a call to the viFlush() operation with a read flag set. The only rule for automatically flushing the read buffer is in response to the viSetBuf() operation. However, as with the write buffer, you can use an attribute to control how to flush the buffer: VI_ATTR_RD_BUF_OPER_MODE. If the attribute is set to VI_FLUSH_DISABLE, the buffer is flushed only when an explicit call to viFlush() is made. If this attribute is set to VI_FLUSH_ON_ACCESS, the buffer is flushed at the end of every call to viScanf().
In addition to the preceding rules and attributes, the formatted I/O buffers of a session to a given device are reset whenever that device is cleared through the viClear() operation. At such a time, the read and write buffer must be flushed and any ongoing operation through the read/write port must be aborted.
Related Topics
Formatted I/O Read and Low-Level I/O Receive Buffers
Formatted I/O Write and Low-Level I/O Transmit Buffers