Multiple Asynchronous Serial Port Data Processing Techniques

Updated Jan 10, 2018

Reported In

Driver

  • NI-VISA

Issue Details

I am trying to read from multiple serial ports asynchronously at different buad rates, but I am having trouble timing my VISA reads properly to acquire all the data efficiently. I either miss data or use 100% of my CPU at run time. How can I solve this dilemma?

Solution

LabVIEW provides several powerful serial input/output and string processing VIs. The proper use of these will lead to efficient application design. Though there is no "one way" to code your program, the easiest way to avoid many concerns is to use the "Bytes at Port" properly. This returns the number of bytes currently available at a serial port used by a VISA session. By wiring this number directly to the "byte count" input of the VISA Read, you may achieve optimal performance from your serial application. Observe the following block diagram as an example.

Additional Information


Several techniques may be employed to make your LabVIEW serial application less processor intensive. The timing VIs, such as Wait Until Next Multiple, are one example of how to dictate the priority of different threads within your application. When working with multiple serial ports, placing separate VISA Read VIs in their own while loops is certainly one method of handling data transfers using these timing VIs, though it may not be the simplest.

Synchronous and asynchronous I/O functions are also a consideration. For example, the behavior of the VISA Read VI may change significantly within the scope of your application, hinging on the structure of your block diagram and the state of the LabVIEW development environment. If you are running LabVIEW in single-threaded mode, and the VISA Read is synchronous, then it will block the entire application from running while it waits for the number of bytes specified at the byte count input. But, if LabVIEW is in multi-threaded mode and the VISA Read is synchronous, only the thread that called the operation will block. If on the other hand the VISA Read is asynchronous, the rest of your application will not block, regardless of whether it is single or multi-threaded. Only that portion of the diagram with dataflow dependency on the VISA Read will be affected. 

Many LabVIEW VIs may be successfully developed without the need for attention to CPU processing speed, multi-tasking, muti-threading, etc. However, applications which must interface with real-time asynchronous inputs may require special care to avoid pacing the application or operating system. VISA read's and write's are no exception to this guideline. Please refer to the "Related Links" section below for more information.

WAS THIS ARTICLE HELPFUL?

Not Helpful