Controlling the Serial I/O Buffers

NI-VISA

Controlling the Serial I/O Buffers

The viFlush() and viSetBuf() operations also provide a control mechanism for the low-level serial driver buffers. The default size of these buffers is 0, which guarantees that all I/O is flushed on every access. To improve performance, you can alter the size of the low-level I/O transmit buffer or low-level I/O receive buffer by invoking the viSetBuf() operation with the VI_IO_OUT_BUF or VI_IO_IN_BUF flag, respectively. When the buffer size is non-zero, I/O to serial devices is not automatically flushed. You can force the low-level I/O transmit buffer to be flushed by invoking the viFlush() operation with VI_IO_OUT_BUF. Alternatively, you can call viFlush() with VI_IO_OUT_BUF_DISCARD to empty the low-level I/O transmit buffer without sending any remaining data to the device. You can also call viFlush() with either VI_IO_IN_BUF or VI_IO_IN_BUF_DISCARD to empty the low-level I/O receive buffer (both flags have the same effect and are provided only for API consistency).

Note  Not all VISA implementations may support setting the size of either the low-level I/O receive or transmit buffers. In such an implementation, the viSetBuf() operation will return a warning. While this should not affect most programs, you can at least detect this lack of support if a specific buffer size is required for performance reasons. If serial buffer control is not supported in a given implementation, we recommend that you use some form of handshaking (controlled via the VI_ATTR_ASRL_FLOW_CNTRL attribute), if possible, to avoid loss of data.

When using formatted I/O in conjunction with serial devices, calling viFlush() on a formatted I/O buffer has the same effect on the corresponding serial buffer. For example, invoking viFlush() with VI_WRITE_BUF flushes the formatted I/O output buffer first, and then the low-level I/O transmit buffer. Similarly, VI_WRITE_BUF_DISCARD empties the contents of both the formatted I/O and low-level I/O transmit buffers.

Note  In previous versions of VISA, VI_IO_IN_BUF was known as VI_ASRL_IN_BUF and VI_IO_OUT_BUF was known as VI_ASRL_OUT_BUF.

Related Topics

Automatically Flushing the Formatted I/O Buffers

Formatted I/O Read and Low-Level I/O Receive Buffers

Formatted I/O Write and Low-Level I/O Transmit Buffers

Manually Flushing the Formatted I/O Buffers

Recommendations for Using the VISA Buffers