Using LabVIEW Real-Time
- Updated2023-09-14
- 5 minute(s) read
Using LabVIEW Real-Time
The LabVIEW Real-Time (RT) module combines LabVIEW graphical programming with the power of a real-time operating system, enabling you to build real-time applications. NI-XNET provides features and performance specifically designed for LabVIEW RT.
High Priority Loops
Many real-time applications contain at least one loop that must execute at the highest priority. This high-priority loop typically contains code to read inputs, execute a control algorithm, and then write outputs. The high-priority loop executes at a fast period, such as 500 µs (2 kHz). To ensure that the loop diagram executes within the period, the average execution time (cost) of read and write VIs must be low. The execution time also must be consistent from one loop iteration to another (low jitter).
Within NI-XNET, the session modes for single-point I/O are designed for use within high-priority loops. This applies to all four single-point modes: input, output, signal, or frame. The XNET Read and XNET Write VIs provide fast and consistent execution time, and they avoid access to shared resources such as the memory manager.
The session modes other than single-point all use queues to store data. Although you can use the queued session modes within a high priority loop, those modes use a variable amount of data for each read/write. This requires a variable amount of time to process the data, which can introduce jitter to the loop. When using the queued modes, measure the performance of your code within the loop to ensure that it meets your requirements even when bus traffic is variable.
When the XNET Read and XNET Write VIs execute for the very first loop iteration, they often perform tasks such as auto-start of the session, allocation of internal memory, and so on. These tasks result in high cost for the first iteration compared to any subsequent iteration. When you measure performance of the XNET Read and XNET Write VIs, discard the first iteration from the measurement.
For another VI or property node (not the XNET Read or XNET Write VI), you must assume it is not designed for use within high priority loops. The property nodes are designed for configuration purposes. VIs that change state (for example, the XNET Start VI ) require time for hardware/software configuration. Nevertheless, there are exceptions for which certain properties and VIs support high-priority use. Refer to the help for the specific features you want to use within a high priority loop. This help may specify an exception.
XNET I/O Names
You can use a LabVIEW project to program RT targets. When you open a VI front panel on an RT target, that front panel accesses the target remotely (over TCP/IP).
When you use an XNET I/O name on a VI front panel on LabVIEW RT, the remote access provides the user interface features of that I/O name. For example, the drop-down list of an XNET Interface provides all CAN, FlexRay, and LIN interfaces on the RT target (for example, a PXI chassis).
For the remote access to operate properly, you must connect the LabVIEW RT target using a LabVIEW project. To connect the target, right-click the target in a LabVIEW project and select Connect. The target shows a green LED in project, and the user interface of I/O names is operational.
If the RT target is disconnected in a LabVIEW project, each I/O name displays the text (target disconnected) in its drop-down list.
Deploying Databases
When you create an NI-XNET application for LabVIEW RT, you must assign an alias to your database file. When you deploy to the RT target, the text database file is compressed to an optimized binary format, and that binary file is transferred to the target.
When you create NI-XNET sessions using a LabVIEW project, you assign the alias within the session dialog (for example, Browse for Database File). When you drag the session to a VI under the RT target, then run that VI, NI-XNET automatically deploys the database file to the target.
When you create NI-XNET sessions at run time, you must explicitly deploy the database to the RT target. There are two options for this deployment:
- I/O names : If you are using I/O names for database objects, you can click on an I/O name and select Manage Database Deployment. This opens a dialog you can use to assign new aliases and deploy them to the RT target.
- File Management VIs : To manage database deployment from a VI running on the host (Windows computer), use VIs in the NI-XNET File Management palette. This palette includes VIs to add an alias and deploy the database to the RT target.
To delete the database file from the RT target after execution of a test, you perform this undeploy using either option described above.
Memory Use for Databases
When you access properties of a database object (for example, cluster, frame, signal) on the diagram of your VI, NI-XNET opens the database on disk and maintains a binary image in memory. Use XNET Database Close.vi to close the database prior to performing memory-sensitive tasks, such as a control loop on LabVIEW Real-Time.
When you pass database objects as input to XNET Create Session.vi, NI-XNET internally opens the database, reads the information required to create the session, then closes the database. Therefore, there is no need to explicitly close the database after creating sessions.
FlexRay Timing Source
FlexRay is a deterministic protocol, which means it enables ECUs to synchronize code execution and data exchange. When you use LabVIEW to test an ECU that uses these deterministic features, you typically need to synchronize the LabVIEW VI to the FlexRay communication cycle. For example, to validate that the ECU transmits a different value each FlexRay cycle, you must read that frame every FlexRay cycle.
NI-XNET provides the XNET Create Timing Source (FlexRay Cycle) VI to create a LabVIEW timing source. You wire this timing source to a LabVIEW timed loop to execute LabVIEW code synchronized to the FlexRay cycle. Because the length of time for each FlexRay cycle is a few milliseconds, LabVIEW RT provides the required real-time execution.
Creating a Built Real-Time
Application
NI-XNET supports creation of a real-time application, which you can set to run automatically when you power on the RT target. Create the real-time application by right-clicking Build Specifications under the RT target, then selecting New»Real-Time Application.
If you created NI-XNET sessions in a LabVIEW project, those sessions are deployed to the RT target in the same manner as running a VI.
Deployment of databases for a real-time application is the same as running a VI.