Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Reading and Writing Shared Variables with Shared Variable Nodes

LabVIEW 2013 Help

Edition Date: June 2013

Part Number: 371361K-01

»View Product Info

(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:

  • Drag a shared variable from the Project Explorer window onto the block diagram of a VI in the same project.
  • Add a Shared Variable node to the block diagram from the Shared Variable palette. You then must complete the following steps to point the Shared Variable node to a corresponding shared variable in the Project Explorer window.
    1. Double-click the Shared Variable node to display the Browse for Variable dialog box.
    2. Navigate to a shared variable in the Project/Network Tree list.
    3. Click the OK button.
  • (Real-Time, FPGA, and DSC Modules) Right-click a control, indicator, or constant and select Change to Shared Variable Node from the shortcut menu. You also can select Create»Shared Variable Node from the shortcut menu when you right-click an output terminal.

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:
    • Select Access Mode»Read to read data from the shared variable with the Shared Variable node. When you select this option, an output appears on the right side of the Shared Variable, as shown in the following figure.

    • Select Access Mode»Write to write data to the shared variable with the Shared Variable node. When you select this option, an input appears on the left side of the Shared Variable node, as shown in the following figure.

      Note  If you write less than 8 kilobytes of data to a shared variable, LabVIEW can take up to 10 milliseconds to send that data over the network. To eliminate this delay, use the Flush Shared Variable Data VI to send the shared variable data immediately.

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.

Note  (Real-Time Module) You cannot access a time-triggered shared variable using a target-relative Shared Variable node.

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.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit