Reading and Writing Shared Variables with Shared Variable Nodes

(Real-Time, Windows) A Shared Variable node is a block diagram object that points to a corresponding shared variable. Use the Shared Variable node to read and write the value of a shared variable.

Note��
  • If your application accesses a large number of shared variables, access the shared variables programmatically to create a cleaner, more scalable block diagram.
  • (Real-Time, Windows) Opening a VI containing a Shared Variable node in a project that does not contain the corresponding shared variable in the Project Explorer window causes the Shared Variable node to break. Any front panel controls associated with the missing shared variable also break. This behavior is specific to Windows and occurs only when you open the VI in a project. If you open the VI in the main application instance, LabVIEW does not notify you about missing shared variables.

Adding Shared Variable Nodes to the Block Diagram

You can add Shared Variable nodes to the block diagram in the following ways:

Specifying Whether a Shared Variable Node Reads or Writes Data

Complete the following steps to specify whether a Shared Variable node reads or writes data to the corresponding shared variable in the Project Explorer window.

  1. Right-click the Shared Variable node.
  2. Choose between the following options in the shortcut menu:

Determining Whether a Shared Variable Value Has Been Updated Since the Last Read

Complete the following steps to use the timestamp indicator of a Shared Variable node to determine whether the shared variable value has been updated since the last read.

Note��
  • LabVIEW configures network-published shared variables for timestamping by default. To record a timestamp value for a single-process shared variable, you first must place a checkmark in the Enable Timestamping checkbox on the Variable page of the Shared Variable Properties dialog box.
  • LabVIEW disables timestamps by default on I/O variable nodes because timestamps require additional memory and CPU overhead that can affect the determinism of an application. Enable timestamps for I/O variable nodes only if you plan to use the timestamps.
  1. Right-click a Shared Variable node and select Timestamp�Show from the shortcut menu. A timestamp output appears on the right side of the Shared Variable node, represented by the red hourglass shown in the following figure.

  2. Right-click the timestamp output and select Create�Indicator from the shortcut menu to create a front-panel indicator that displays the timestamp data.

Determining Whether a Shared Variable Node Timed Out

Complete the following steps to specify a timeout period for the Shared Variable node and determine whether the Shared Variable node timed out.

Note��You can enable the timeout control only for Shared Variable nodes configured to read data.
  1. Right-click the Shared Variable node on the block diagram and select Timeout�Show from the shortcut menu
  2. Specify a timeout in milliseconds with the ms timeout control, represented by the blue clock on the left side of the following figure. Use the timed out? indicator, represented by the red clock on the right side of the following figure, to determine whether the Shared Variable node read new data in the specified time period or timed out.

Specifying Whether Shared Variable Nodes Break When You Move Them to Different Targets

(Real-Time, Windows) To specify how a Shared Variable node connects to a shared variable, you can set the node to absolute or target-relative.

An absolute Shared Variable node always connects to the shared variable on the target on which you created the shared variable. Shared Variable nodes are absolute by default. If a VI contains an absolute Shared Variable node and you open the VI on a new target, the VI breaks because the node attempts to connect to the shared variable on the target on which you created the shared variable. Use absolute Shared Variable nodes when you do not expect to move VIs and variables to other targets.

A target-relative Shared Variable node always connects to the shared variable on the target that runs the VI that containing the Shared Variable node. If you move a VI that contains a target-relative Shared Variable node to a new target, you also must move the shared variable to the new target because target-relative Shared Variable nodes can connect to shared variables on the local host only. Use target-relative Shared Variable nodes when you are accessing shared variables on the local host and you expect to move VIs and variables to other targets.

To change an absolute Shared Variable node to target-relative, right-click the Shared Variable node on the block diagram and select Reference Mode�Target Relative from the shortcut menu. Target-relative Shared Variable nodes appear with a .\ glyph on the node. The following image shows a target-relative Shared Variable node.

To change a target-relative Shared Variable node to absolute, right-click the Shared Variable node and select Reference Mode�Absolute from the shortcut menu. The following image shows an absolute Shared Variable node.

Data Communication Methods Home