Shared Variable Node

Owning Palette: Shared Variable Node, VI, and Functions

Requires: Base Development System (Real-Time, Windows)

Represents a shared variable on the block diagram. To bind a Shared Variable node to a shared variable from the active project, add a Shared Variable node to the block diagram and double-click or right-click the node and select Select Variable»Browse from the shortcut menu to display the Browse for Variable dialog box. You also can drag a shared variable from the Project Explorer window onto the block diagram of a VI in the same project to create a Shared Variable node.

Note  The behavior of the Shared Variable node differs when it is bound to a physical I/O channel. Refer to the Using I/O Variables topic for information about I/O variables.

Details  

 Add to the block diagram  Find on the palette
Variable specifies the value to write to the Shared Variable node. You must wire a value to this input when the Shared Variable node is configured to write data, or the VI will be broken. This input is available only when the Shared Variable node is configured to write data.
ms timeout specifies a timeout period in milliseconds for a Shared Variable node configured to read data. The shared variable waits the specified amount of time for updated data, and the timed out? indicator returns whether the shared variable received updated data in the specified time period or timed out. Updated data can represent a new value or an existing value that simply confirms a valid connection with the shared variable in the active project. To add a ms timeout input to the Shared Variable node, right-click the Shared Variable node and select Show Timeout from the shortcut menu. You only can enable a timeout period for Shared Variable nodes configured to read data. You cannot enable a timeout period for nodes that access I/O variables locally.
error in describes error conditions that occur before this node runs. This input provides standard error in functionality.
Variable specifies the current value of the shared variable that the Shared Variable node represents. This output is available only when the Shared Variable node is configured to read data. If the Shared Variable node times out, Variable returns the value that the node last read. If the node times out before reading any data or if the type of data is incompatible, data returns a value of 0, empty, or an equivalent value.
timed out? displays whether a Shared Variable node read new data within the specified timeout period or timed out. To add a timed out? output to the Shared Variable node, right-click the Shared Variable node and select Show Timeout from the shortcut menu. You only can enable a timeout period for Shared Variable nodes configured to read data. You cannot enable a timeout period for nodes that access I/O variables locally. If the timeout expires, the Shared Variable node returns the last value written to the variable and does not return an error.
timestamp displays the timestamp data for the shared variable. To add a timestamp output to the Shared Variable node for a single-process shared variable or an I/O variable, you must first place a checkmark in the Enable timestamp checkbox on the Variable page of the Shared Variable Properties dialog box, and then right-click the Shared Variable node and select Show Timestamp from the shortcut menu. You can use this output only with shared variable nodes that are configured to read data.
error out contains error information. This output provides standard error out functionality.

Shared Variable Details

When you drag a shared variable from the Project Explorer window to the block diagram or place a Shared Variable node on the block diagram, LabVIEW configures the Shared Variable node to read data. To configure the Shared Variable node to write data, right-click the Shared Variable node and select Change to Write from the shortcut menu.

Note  You can create, configure, and host shared variables only on Windows, RT targets, and certain PDA targets. You can use the DataSocket VI and functions to read or write shared variables from other platforms.

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. A target-relative Shared Variable node always connects to the shared variable on the target on which you run the VI that contains the Shared Variable node. To change an absolute Shared Variable node to target-relative, right-click the Shared Variable node and select Reference Mode»Target Relative from the shortcut menu. 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.

Note  Opening a VI containing a Shared Variable node in a project where the Shared Variable node cannot find its associated 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.

(Windows) This behavior is specific to Windows and only occurs when you open the VI in a project. If you open the VI in the main application instance, you do not receive notification of missing shared variables.

A network-published Shared Variable node on a VI uses an .aliases file to determine the IP address of the computing device in the project where the Shared Variable is deployed. When you run a VI in a LabVIEW project, the VI finds the project's .aliases file and uses that to resolve aliases. The project keeps entries for each computing device in the project in the .aliases file, and updates the IP addresses when they change. When the VI runs in the main application instance, the VI uses the LabVIEW.aliases file in the same directory as LabVIEW.exe to find aliases. This file does not update automatically like the project .aliases file. When building an application that uses shared variables, ensure that the build specification includes the .aliases file.

You must add the IP address to the .aliases file. If the VI fails to find the alias, the Shared Variable node uses the last known IP address. If the shared variable is no longer deployed at the last known IP address, the Shared Variable node will return an error.

If you publish a shared variable with less than 8 kilobytes of data, it can take up to 10 milliseconds for LabVIEW to send that data over the network. The Flush Shared Variable Data VI allows you to flush the buffer immediately and eliminate this delay.

Note  You can right-click a Shared Variable node and select Replace with Programmatic Access from the shortcut menu to switch to programmatic access. By using programmatic shared variable access, you can create clean, scalable block diagrams.