Reading and Writing Shared Variable Values Deterministically

After you create a shared variable, you can access the shared variable data from VIs using a Shared Variable node. A Shared Variable node is a block diagram object that references a shared variable in the Project Explorer window. Use a Shared Variable node to read and write values to a shared variable. Drag a shared variable from the Project Explorer window to the block diagram of a VI to create a Shared Variable node.

You also can place a Shared Variable node from the Data Communication palette on the block diagram. To bind a Shared Variable node on the block diagram to a shared variable in the active project, right-click the Shared Variable node and select Select Variable»Browse from the shortcut menu to open the Browse for Variable dialog box. Select a shared variable from the tree control and click the OK button.

By default, the Shared Variable node is set to read. To change the Shared Variable node on the block diagram to write, right-click the Shared Variable node and select Change to Write from the shortcut menu.

Sharing Data Locally on the RT Target

Use a single-process shared variable with the real-time FIFO enabled to share data between two locations in a block diagram that cannot be connected with wires or between two VIs running on an RT target. Enabling the real-time FIFO of a shared variable ensures that sharing data from deterministic sections of a block diagram or VIs running on an RT target does not affect the determinism of the section of the block diagram or VI.

The following block diagram shows a VI that runs on an RT target and uses two Timed Loops to acquire waveform data and then log the data to file. The VI uses a single-process shared variable with the real-time FIFO enabled, RT_Single-Process, to share data between a deterministic Timed Loop, labeled Deterministic Acquisition Loop, and a lower priority Timed Loop, labeled Data Logging Loop. With the real-time FIFO of the shared variable enabled, the Deterministic Acquisition Loop can share data with the Data Logging Loop without affecting the determinism of the data acquisition.

Sharing Data with a Remote Target

Use a network-published shared variable with the real-time FIFO enabled to share data between VIs on different targets. enabling the real-time FIFO of a shared variable ensures that sharing data from a deterministic VI across a network does not affect the determinism of the VI.

The following block diagram shows a VI that runs on a host computer and publishes a Boolean value to stop a VI on an RT target. The host VI writes the Boolean value to a network-published shared variable with the real-time FIFO enabled, RT_Network-Published.

By enabling the real-time FIFO of the shared variable, the Deterministic Acquisition Loop in the following block diagram can receive data from across a network without affecting the determinism of the data acquisition. You also can share data from the Deterministic Acquisition Loop using a network-published shared variable with the real-time FIFO enabled.