|Download Help (Windows Only)|
You can use shared variables to read and write data among VIs in a project or across a network. From the Project Explorer window, right-click an RT target and select New»Variable from the shortcut menu to open the Shared Variable Properties dialog box, which you can use to create and configure the options for a shared variable. Shared variables are configured software items that can send data between two locations in a block diagram that cannot be connected with wires, between two VIs running on an RT target, or between two VIs across a network running on different targets. Use single-process shared variables to share data locally on an RT target, network-published shared variables to share data between VIs on different machines for data logging, and time-triggered shared variables to share data between VIs on different machines for control, automation, and simulation.
The Real-Time Module adds real-time FIFO capability to the shared variable. By enabling the real-time FIFO of a shared variable, you can share data without affecting the determinism of the VIs. However, RT FIFOs do not support data types of variable size, such as clusters, strings, and variants.
|Note Refer to the NI website for performance benchmarks and advanced programming concepts related to shared variables.|
Use the Shared Variable Properties dialog box to create a shared variable on an RT target. To access this dialog box, right-click the target or a library under the target in the Project Explorer window and select New»Variable from the shortcut menu. When you select New»Variable on a target, you create a new library under the target and add the variable under that library. When you select New»Variable on an existing library, you create a new variable under that library. Right-click a library and select Deploy from the shortcut menu to deploy the shared variable to the target.
|Note LabVIEW automatically deploys variables when a VI that calls them runs, unless you disable auto-deployment for the RT target.|
When you create a network-published shared variable on a target, the Shared Variable Engine on the target hosts the shared variable. The Shared Variable Engine sends the data you share to other targets across the network. You can choose the target that you want to host the shared variable by creating the shared variable under the target in the Project Explorer window.
When an RT target hosts a network-published shared variable, that target controls the data and other targets do not affect the availability of the shared variable. If availability is not a concern, consider hosting the shared variable on the host computer. This frees up processor time on the target, permits the shared variable to be accessed by targets that do not support the Shared Variable Engine, and allows you to use the security features provided by the LabVIEW DSC Module.
The following illustration shows a Real-Time Module application that uses single-process and network-published shared variables to share data locally and across the network between VIs:
The Deterministic VI running on the RT target shares data with Other VI on the target using variable B, a single-process shared variable. The Deterministic VI also shares data with a VI on the host computer using variable A, a network-published shared variable with the RT FIFO enabled. The network-published shared variable on the RT target sends data to the Shared Variable Engine running on the target, which then shares the data with the host computer.
|Note You must install Network Variable Engine and Variable Client Support software on an RT Target to host network-published shared variables on that target. RT targets require at least 32 MB of RAM to run the Shared Variable Engine. However, you can install Variable Client Support software on targets with less than 32 MB of RAM to enable them to reference network-published shared variables hosted on other machines.|
After you create a shared variable, you can use the Shared Variable Properties dialog box to change its configuration. To open this dialog box, right-click a shared variable in the Project Explorer window and select Properties from the shortcut menu. When you change a shared variable's properties, those changes do not take effect until the variable is deployed.
You can enable the real-time FIFO of a shared variable from the Real-Time FIFO page of the Shared Variable Properties dialog box. Place a checkmark in the Enable Real-Time FIFO checkbox to deterministically share data using single element or multi-element FIFOs.
A single-element FIFO shares the most recent data value. The shared variable overwrites the data value when it receives a new data value. Use this option when you need only the most recent value. Configure the size of the array elements or the size of the waveform for the FIFO buffer if you select an array or waveform data type.
A multi-element FIFO buffers the values shared by the shared variable. You can configure the size and the elements of the FIFO buffer to match the settings from the Use Buffering section of the Network page, or you can configure a custom size for the FIFO and the FIFO elements.
|Note For both single-element and multi-element FIFOs, if the variable contains array or waveform data, you must configure the size of the FIFO elements equal to the size of the data you want to share. If both the network buffer and the RT FIFO are enabled, the network buffer must be at least as large as one FIFO element. Sharing data smaller or larger than the length you specify causes a memory allocation that affects determinism.|
|Note Waveforms contain variable-size variant elements that are not compatible with the Real-Time FIFO. Therefore, if you enable the Real-Time FIFO on a shared variable that contains waveform data, the variant element of the waveform data does not transfer.|