The Shared Variable is a simplified programming interface for sharing data that was introduced in LabVIEW 8. Using the network-published Shared Variable, you easily can pass data within a system and between systems.Once a Shared Variable has been created using the Network-Published scope, all data written to the variable is available to all systems networked with the host computer. Shared Variables are configured through dialogs accessable from the Project Explorer window. You can also add data services to Shared Variables such as logging, alarming, and events, through dialogs using the LabVIEW Datalogging and Supervisory Control Module. The Shared Variable Engine manages the use, connectivity, and performance of all Shared Variables on your many data acquisition and control systems, and it does this using the NI Publish-Subscribe Protocol (NI-PSP). An in-depth discussion of the Shared Variable Engine can be found in the tutorial Buffered Network-Published Shared Variables: Components and Architecture, while more information about NI-PSP can be found in the LabVIEW Help: Understanding Shared Variable Technology. For more information on Shared Variable configuration, reference the tutorial Using the LabVIEW Shared Variable.
OPC, originally an abbreviation for Object Linking and Embedding for Process Control, is a standard first developed in 1996 by the OPC Foundation. The standard specified the communication of plant data between control devices from different manufacturers. More information about OPC can be found in the tutorial What is OPC?.
Figure 1. OPC is intended to improve enterprise system connectivity.
The NI Shared Variable Engine includes an OPC Server so that Shared Variable data can be made available to OPC client applications. The Shared Variable Engine publishes all variables as OPC tags under the Prog ID National Instruments.Variable Engine.1. The Shared Variable Engine can use the OPC Data Access 2.0 or 3.0 standard, allowing any device compatible with those OPC DA standards to access the data stored in a Network-Published Shared Variable.
In addition to its role as the primary device driver for NI data acquisition devices, NI-DAQmx uses NI-PSP to interact with the Shared Variable Engine and make data read by the driver available to all networked devices. NI-DAQmx automatically produces PSP objects for all NI-DAQmx global virtual channels configured in MAX and all NI-DAQmx local channels created in LabVIEW, though it does not publish data from NI-DAQmx tasks.
As discussed previously, the Shared Variable Engine publishes all Shared Variables as OPC tags; therefore, the Shared Variable Engine makes it possible for an OPC DA client to read and write data to an NI-DAQmx device.
Figure 2. NI-DAQmx works with the Shared Variable Engine to make DAQ hardware available for OPC connectivity.
This functionality makes it easy to perform data acquisition or generation using LabVIEW, the Distributed System Manager, or a third-party OPC client. To access an NI-DAQmx channel via NI-PSP, you must first bind the channel to a Shared Variable. This will be shown later in the tutorial.
Figure 3. A simple data acquisition task using a Shared Variable bound to an NI-DAQmx input channel.
The NI Distributed System Manager can be used to view NI-DAQmx channels, as well as any Shared Variables which are bound to those channels. However, it can not log that data without using the LabVIEW DSC module and a Shared Variable bound to the NI-DAQmx channel. For a description of how to log data to the NI Citadel 5 database, see the tutorial Logging Data with NI Citadel.
Figure 4. A view of the NI-DAQmx channel, TTL Input, and bound Shared Variable, TTL Channel, in the Distributed System Manager.
As previously discussed, an OPC client can access the data published by NI-DAQmx channels and the Shared Variable Engine. OPC Quick Client, shown below, demonstrates this use case. The Quick Client is included with the NI LabVIEW Datalogging and Supervisory Control Module.
Figure 5. The NI-DAQmx channel and bound Shared Variable in the OPC Quick Client
The steps required to view a Shared Variable in the OPC Quick Client can be found below.
A Shared Variable can be bound to both local (project) and global (MAX) NI-DAQmx Virtual Channels. The scope of the channel determines its behavior. Project NI-DAQmx Channels only broadcast data when the Shared Variable to which they are bound is deployed. That is, NI-DAQmx Channels created in a project must be bound in order to be used. Global NI-DAQmx Virtual Channels, on the other hand, constantly output data.
Drag the variables from the Project Explorer windows into the block diagram. In the example below, the Shared Variables will be read with each iteration of the loop. When you are using a Network-Published Shared Variable, you also have the option to create a Shared Variable for the polling rate. The server polling rate determines how often the Shared Variable gets new data from its bound global channel.
To access Shared Variables from the OPC Quick Client that ships with the LabVIEW DSC Module, you must locate the Shared Variable Engine, and then create items for the tags associated with each Shared Variable.
Collaborate with other users in our discussion forums
A valid service agreement may be required, and support options vary by country.