Buffer Overflow with Serial Port When Using VISA with Flow Control

Updated Jan 24, 2019

Reported In

Driver

  • NI-VISA

Operating System

  • Windows
  • NI Linux Real-Time

Other

  • PXI/CompactPCI Controllers

Issue Details

My serial port is reporting a buffer overflow and I am using NI-VISA with hardware or software flow control. Why is the flow control not preventing FIFO overflows?
 

Solution

This problem can be caused by several factors. These include the speed of your computer, the baud rate that you are using, the size of your serial port's FIFO, and the FIFO size of the instrument that is transmitting data to the serial port.

The flow control will wait until a specific number of bytes are in the buffer before asking the processor to send a message or signal to the other device to quit transmitting. At higher baud rates the serial port will receive a few bytes from the time the buffer flow control level is reached and the instrument stops transmitting. These extra bytes coming in will be greater if a higher priority process has control of the real-time target's processor. Since the process is a higher priority than the VISA interrupt, no action will be taken by the processor until the higher priority process is finished with the real-time processor.

The default VISA and Windows settings for a 16 byte FIFO is 14 bytes leaving 2 bytes in the FIFO when the device attempts to send the message to the sending device. At higher baud rates on slower computers it is very possible to receive more than 4 bytes from the time the serial port requests the processor to send the signal the instrument finally stops transmitting.

On LabVIEW Real-Time or using a NI Serial hardware
Open MAX and locate the serial port that is having the problem under Devices and Interfaces. After clicking on the COM port an Advanced Settings tab should appear in the right pane. These settings should allow you to lower the Receive Buffer size. You should lower the buffer size until the issue is resolved. 



Depending on the loading of the system (e.g. long periods of time spent in high priority tasks or loops), you may be more likely to starve serial hardware processing tasks. This can result in more RX FIFO overruns since the serial hardware isn't being serviced often enough. To avoid this, configure NI-Serial's interrupt handling mode. SecondaryInterrupts = 1 has been the default behavior since the token was introduced in 3.1. It was renamed to InterruptProcessingLevel in version 3.8. Please see Performance on LabVIEW Real-Time in the NI-Serial Help for more information on configuring the interrupt handling mode. This setting has no effect for C Series modules.

On Compact RIO and FieldPoint
Open MAX and find the serial ports attached to the controller, you will notice that Advanced Tab does not appear. Instead of using this tab to set the request level for raising the hardware flow control line, we must modify a file located on the controller. Modify the niserial.dbs file located in the c:\ni-rt\system directory on the controller. Directly under the line SerialPortName = "COM1" add the following lines: RXFIFO = 1. The possible values for the RXFIFO are 1, 4, 8, and 14. Modifying this file will allow you to change the trigger level of the hardware flow control.

On Windows
To fix this problem you need to open up the Device Manager in Windows. Then, find the COM port you want to modify the settings for and open up it's properties. Next, click on the Advanced Tab. You will see a slider that should allow you to change the size of the receive buffer, so that the UART will enable the flow control sooner. 



The default value should be sufficient in most cases. However, if you are getting buffer overflow errors you should decrease this value. This will cause more interrupts to be sent to the processor and slow the bytes into the UART. If you increase this value bytes may overflow the FIFO buffer.

Additional Information

For serial communication it is critical to understand the buffer sizes, FIFO settings, baud rates and priorities that the VISA process in the processor.