Shared variables are configured software items that can send data between VIs. Use shared variables to share data among VIs or between locations on the block diagram that you cannot connect with wires. A shared variable can represent a value or an I/O point. You can change the properties of a shared variable without having to edit the block diagram of the VIs that use the shared variable.
|Note You can create, configure, and host shared variables only on Windows or RT targets with the LabVIEW Real Time Module. You can use the DataSocket VI and functions to read or write shared variables from other platforms.|
You can share data using shared variables with little or no block diagram programming. Configuration options for shared variables, such as buffering and single-writer restriction, are available through the Shared Variable Properties dialog box. The Variable Type pull-down menu configures whether the shared variable can share data on the local computer or across a network. Select Network-Published from the Variable Type list to create shared variables that you want to read and write on remote computers and targets on the same network. Select Single-Process from the Variable Type list to create shared variables that you want to read and write on a single computer. Single-process shared variables are target-relative. Configuration options vary depending on the Variable Type you select. LabVIEW modules and toolkits you have installed might provide additional shared variable types, configuration options, and limitations. Refer to the documentation for the LabVIEW module or toolkit for more information about the shared variable types, configuration options, and limitations that product adds to shared variables.
|Note (Windows, ETS, VxWorks) If you are using a network-published Shared Variable node that is configured to read data, you must run each Shared Variable node before the node subscribes and starts receiving buffered values.|
Shared variables must exist within a project library. LabVIEW stores shared variable configuration data in the .lvlib file for the project library that contains the shared variable.
|Note (Windows, ETS, VxWorks) 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. 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.|
The Shared Variable Engine (SVE) uses the NI Publish-Subscribe Protocol (NI-PSP) to enable the data transfer of network-published shared variables through a network. The SVE manages the use and connectivity of shared variables on single or multiple systems.
Network-published shared variables communicate between VIs, remote computers, and hardware through the SVE. LabVIEW identifies network-published shared variables through a network path that includes the computer name, project library name(s), and shared variable name.
Project libraries that LabVIEW deploys to the SVE are called processes. When you deploy a project library that contains shared variables, LabVIEW deploys the library to the SVE. The SVE creates a process corresponding to the library. The SVE also creates all the shared variables that are in the library for the process. When you add new shared variables to the library and then redeploy the library, the SVE creates the new shared variables in the process. When you modify the existing shared variables in the library and then redeploy the library, the SVE updates the existing shared variables you change in the process. When an application runs, the SVE manages the process and the data transfer of the shared variables.
You must configure firewalls and Network Address Translating (NAT) routers if you want to transmit network-published shared variables through the firewalls or routers.
You can configure a shared variable to have a data source. Possible data sources for shared variables include DAQ channels, data items, NI-PSP data items, such as other shared variables, and data items from I/O servers that are defined outside of the active project. For example, you might choose to define a FieldPoint data item as the data source of a shared variable. The FieldPoint process monitors the values that the hardware acquires. When the FieldPoint process sends new data to the Shared Variable Engine (SVE), the SVE updates the shared variable value.
Configure a shared variable to have a data source by placing a checkmark in the Enable Aliasing checkbox on the Variable page of the Shared Variable Properties dialog box.
When you configure a shared variable to have an existing data source across a network, LabVIEW does not track configuration changes to the data source. Therefore, changes to the data source could break the connected shared variable. For example, suppose you create a shared variable named VarSource in one project, and in a separate project, you create a second shared variable, VarDest. You now want to make the VarSource shared variable the data source for the VarDest shared variable. Because the data source you want to use is outside of the active project, you must browse the network to select the data source. After you create and configure the VarDest shared variable, LabVIEW retains the URL and configuration. Now, any configuration changes you make to the VarSource shared variable are unknown to the VarDest shared variable. If you change the variable name for VarSource, the URL in the destination project is broken, and you need to update the configuration of VarDest with the new name of VarSource.
You must have a project open to create a shared variable. To add a shared variable to a project, right-click a target, a project library, or a folder within a project library in the Project Explorer window and select New»Variable from the shortcut menu to display the Shared Variable Properties dialog box. Select among the shared variable configuration options and click the OK button.
|Note When you create a shared variable, consider how you want Shared Variable nodes to connect to the shared variable.|
Shared variables must be inside project libraries. If you create a shared variable from a target or folder that is not inside a project library, LabVIEW creates a new project library and places the shared variable inside.
|Note LabVIEW modules and toolkits you have installed might not support shared variables.|
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.
Each shared variable on a target has a location that NI-PSP uses to identify the shared variable. Right-click the project library for the shared variable and select Deploy from the shortcut menu to deploy the library. You must deploy the owning library to connect to the shared variable from front panel objects, (Windows, ETS, VxWorks) Shared Variable nodes on the block diagram, and other shared variables. (RT Module) You also can right-click the computing device and select Deploy All to deploy all project libraries for shared variables on that target. Deploy All also opens and deploys any VIs that contain the shared variables on that target.
|Note LabVIEW automatically deploys the project libraries for shared variables that you read or write in a VI if the projects containing those variables are open.|
You also can use the NI Distributed System Manager to edit, create, and monitor shared variables outside of the project environment.
|Note If you deploy a LabVIEW project library that includes shared variables and then use the NI Distributed System Manager to create new shared variables in the same project library, the new shared variables only exist until you deploy the project library again.|
If you have RT, FPGA, DSC, or an Embedded module installed, Change to Shared Variable Node appears as a new option in the shortcut menu when you right-click a control, indicator, or constant. You also can select Create»Shared Variable Node from the shortcut menu when you right-click an output terminal.
You can change the shared variable configuration by right-clicking the shared variable in the Project Explorer window and selecting Properties from the shortcut menu to display the Variable page of the Shared Variable Properties dialog box.
By default, multiple applications can write to a shared variable. However, you can set a network-published shared variable to accept changes in value from only one application at a time by placing a checkmark in the Single Writer checkbox in the Network page of the Shared Variable Properties dialog box. This ensures that the shared variable write operation is not affected by another writer. The Shared Variable Engine restricts writing to a single source on a single computer. The first writer that connects to the shared variable can write values, and any subsequent writers cannot. When the first writer disconnects, the next writer in the queue can write values to the shared variable. LabVIEW notifies writers that are not allowed to write to the shared variable.
After you change the configuration for a shared variable, right-click the project library in which the shared variable resides under the target and select Deploy from the shortcut menu to update the properties of the shared variable on the target. You also can use the Variable Reference property with the Variable properties to configure shared variables programmatically.
|Note You also can configure Shared Variable nodes on the block diagram.|
If you plan to distribute a stand-alone application that uses shared variables, do not include the .lvlib file in an LLB or in the executable. Use the Source File Settings page of the Application Properties dialog box to change the Destination of the .lvlib file to a destination outside the executable or LLB. You can deploy the shared variables in three ways:
If you plan to distribute a shared library that uses shared variables, do not include the .lvlib file in the shared library. Use the Source File Settings page of the Shared Library Properties dialog box to change the Destination of the .lvlib file to a destination outside the shared library.
The Shared Variable Engine reports server status updates and critical errors, such as invalid process configurations. You can view these errors in the Windows Event Viewer. In the Windows Control Panel navigate to the Event Viewer in the Administrative Tools directory. The exact location of the Administrative Tools directory varies depending on which version of Windows you use.