To develop real-time programs, you can use either LabVIEW graphical programming, the LabWindows™/CVI ANSI C environment (for Phar Lap), or a Linux-Compatible C/C++ Development environment of your choice (for NI Linux Real-Time).
Development Option: LabVIEW Real-Time Graphical Programming
Figure 1. Graphical Programming using LabVIEW.
To program NI-supported real-time hardware graphically, you must use LabVIEW along with the LabVIEW Real-Time Module. LabVIEW Real-Time gives you the ability to create reliable, hard real-time applications, download them to hardware, and debug and run them using one tool.
You can use most of the built-in math and signal processing algorithms that come with LabVIEW in your real-time applications, including several proportional integral derivative (PID) control functions. In addition, you can run textual math scripts on your real-time system with the MATLAB node, or integrate models that you create in The MathWorks, Inc. Simulink ® software or other modeling environments using the optional LabVIEW Model Interface Toolkit.
LabVIEW Real-Time: Developing, Downloading, and Running Applications
When developing real-time applications in LabVIEW, you use the LabVIEW Project Explorer to organize your programs (VIs) and assign the hardware that they will run on. You will develop your code on a general-purpose Windows host computer, and then deploy to your real-time hardware over Ethernet or USB connection.
Figure 2. Manage LabVIEW programs (VIs) and assign them to real-time targets using the LabVIEW Project Explorer.
Developing real-time programs in LabVIEW is nearly identical to developing standard LabVIEW applications for your PC. Several additional functions specific to real-time systems are included in the Real-Time VIs palette, including:
- Watchdog functions to automatically restart some hardware targets if your program stops running
- Functions to communicate data deterministically between parts of a real-time program
- Utilities to configure load balancing on systems with multiple CPU cores
- Timing functions to precisely control the execution of loops in your real-time programs
To test your LabVIEW Real-Time code on your hardware, simply click the run arrow and your application will deploy to your real-time hardware and begin running. You can use standard NI debugging tools such as highlight execution, single stepping, and breakpoints from your development computer, even though your real-time program is actually running on the real-time target.
When you have finalized your real-time program, you can build an executable in LabVIEW and download it to your real-time hardware as a startup application. After rebooting your real-time hardware, your program will automatically run in a reliable, stand-alone fashion.
LabVIEW Real-Time: Assigning Priorities to Parallel Code Sections and Multicore Processing
The dataflow programming model of LabVIEW frees you from the sequential architecture of text-based programming languages. Because the execution order is determined by the flow of data between nodes, you can easily create applications that execute multiple operations in parallel. Additionally, LabVIEW makes it easy to assign thread priorities with the Timed Loop structure. As shown below, each loop has a configurable timing source, period, priority, and more.
Figure 3. Specify the priority and processor assignment of different code sections using the LabVIEW Timed Loop structure.
LabVIEW Real-Time supports multicore processing and automatically maps parallel sections of your code to individual OS threads, which eliminates the need to manually create and manage them. By default, these threads are also automatically balanced across the CPUs available on your real-time hardware.
To further increase the performance and reliability of a real-time system, you can choose to manually assign Timed Loops to specific processor cores if wanted. For example, you can dedicate one core of a processor to execute one time-critical loop and isolate it from less important tasks that run on different cores.
Troubleshooting Option: Debugging With the Real-Time Trace Viewer
For advanced multicore debugging, you can use the Real-Time Trace Viewer to verify the performance of your LabVIEW or LabWindows/CVI real-time programs without halting or pausing execution of the code. With minimal modifications to your real-time code, you can log application performance to a file and send it to a host computer for viewing and analysis. The trace tool viewer graphically displays multithreaded code execution while highlighting thread swaps, mutexes, and memory allocations. You can use the Real-Time Trace Viewer to optimize application performance by identifying unwanted execution characteristics and difficult-to-find race conditions.
Development Options for C and C++
If your organization standardizes on C or C++, you can use the LabWindows/CVI development environment or other development environments. Note that LabWindows/CVI Real-Time supports only the real-time PXI controllers, while targets that use NI Linux Real-time, such as CompactRIO Controllers, are open source, so you can use the development tools of your choice. For more information about using C/C++ Development Tools for Linux-Real Time, visit Getting Started with C/C++ Development for NI Linux Real-Time.