Preventing LabVIEW from Continuously Polling the Serial Port

Updated Nov 28, 2017

Reported In

Software

  • LabVIEW Full

Driver

  • NI-VISA

Issue Details

When I read from my serial port, LabVIEW continuously polls for data until the data is available on the port. This increases my processor and resource usage and prevents other loops in my program from executing smoothly. How can I prevent this?

Solution

This issue can be resolved by using VISA events. A VISA event can be generated when a serial character arrives at the port using the VISA Enable Event function. Within a while loop, you can then place a VISA Wait on Event function before the VISA Read function.

The VISA Read will be executed only when a character is received at the serial port. Until the data arrives at the serial port, the thread containing the VISA Wait on Event function is suspended. Therefore, the VISA Read function is executed only when data is available at the port. By specifying the number of bytes to read as 1, you ensure that the serial port is polled only when data is available. Before the program stops, a VISA Disable Event function is used to close the event before closing the VISA session.

These functions can be found in LabVIEW on the block diagram functions palette by browsing to: Instrument I/O»VISA» Advanced»Event Handling.

Additional Information

For more information on the VISA Wait on Event function, please refer to the LabVIEW Help.

WAS THIS ARTICLE HELPFUL?

Not Helpful