Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: May 7, 2007

Network Variable Technical Overview

3 ratings | 4.00 out of 5
Print

Overview

Getting diverse hardware and software components linked together has always had a few challenges. For example, configuring hardware requires consideration of signal levels, impedance, and much more. Software has its own set of challenges. A good example is porting data into and out of applications. First, you must measure the raw data, which is done using tools such as high-performance libraries for instrument control and data acquisition. Second, you must communicate between programs using another set of technologies. Some applications simply save results to a file, while others use custom TCP/IP networking solutions, DDE, or ActiveX. Each I/O mechanism has its unique nuances and requires certain expertise to implement.  This complexity forces a programmer to negotiate between the different protocols to transfer data, which requires a great deal of development time and resources.

As a solution, National Instruments offers Network Variables that simplifies data exchange between applications on the same system, or across the network.  You can also use the network variable application programming interface (API) to pass data between real-time systems without impacting performance. The API is designed in a way to abstract the low level communication protocol, such as TCP/IP or DDE, while being flexible enough to support a wide variety of measurement data types, such as scalars, multidimensional arrays and structs.

Measurement-Specific Protocol

NI designed network variable technology from the ground up to meet the needs of measurement and automation engineers. For example, with TCP/IP, you have to write code to convert your measurement data to an unstructured stream of bytes in the broadcasting application, as well as code to parse the stream of bytes back into its original form in subscribing applications. Network variables, however, transfer data in a self-describing format that can represent data in a wide array of formats, including strings, scalars, Boolean values, and waveforms. The network variable read and write operations transparently convert your measurements to and from the underlying byte streams, eliminating the need to write complicated parsing code. For example, your temperature measurement can not only included the acquire value, but also the timestamp of the acquisition.

The network variable uses the NI Publish-Subscribe Protocol (NI-PSP) to send and receive data across a network. The NI-PSP protocol is built on top of the UDP protocol and therefore takes advantage of the stateless and connection-less aspects. The NI-PSP protocol uses less network bandwidth and is more efficient than TCP/IP for the given requirements of the NI-PSP protocol. Unlike the UDP protocol, however, the NI-PSP protocol guarantees delivery by implementing an additional layer of functionality on top of the raw UDP protocol.

What are Network Variables?

The term network variable refers to software items that exist on a network and can communication between programs, applications, remote computers and hardware.

Figure 1. Network variables reside on a local or remote machine and have associated data types and names.

You reference a network variable by using its path name. The path name is similar to network file share names, such as \\machine\myprocess\item on Windows. In this example, machine is the computer name, IP address, or Fully Qualified Domain name of the server machine that is hosting the variable; myprocess contains network variable folders or variables and is referred to as a network variable process; and item is the name of the network variable. Below are additional examples of network variable references:

  • \\localhost\my_process\my_variable
  • \\test_machine\my_process\my_folder\my_variable
  • \\192.168.1.100\my_process\my_variable
  • \\test_machine.my_network.com\my_process\my_variable
  • \\localhost\System\DAQmx\Server Polling Rate
  • \\localhost\system\my_variable

Network variables consist of three pieces – the Network Variable API,  the Shared Variable Engine, and the NI Variable Manager.

Network Variable Library

The LabWindows/CVI Network Variable Library provides the following functionality:

  • Subscriber - receive new data that is published to a network variable
  • Buffered Subscriber - receive buffered data and get events when buffer is empty, overwritten or stale
  • Writer - update network variable with new data
  • Buffered Writer - asynchronously update published data
  • Reader - read new data stored in a network variable
  • Asynchronous Reader - read new network variable data in an independent thread
  • Data Functions - manipulate network variable data
  • Network Variable Browser Popup - automatically browse for available network variables
  • Browser Functions - create a custom interface to browse network variables.

 

Shared Variable Engine

The Shared Variable Engine (SVE) is a software framework that enables a network variable to transmit live measurement data.  The shared variable engine can be hosted on Windows PCs and real-time targets. On Windows, LabWindows/CVI configures the SVE as a service and launches the SVE at system startup.  On a real-time target, the SVE is an installable startup component (LabWindows/CVI Network Variable for RT) that loads when the system boots. 

In order to use network variables, an SVE must be running on at least one of the nodes in the distributed system. Any node on the network can read or write to network variables that the SVE publishes. You also might have multiple SVEs installed on multiple systems simultaneously if you need to deploy network variables in different locations based on application requirements.

See Also: Shared Variable Engine

NI Variable Manager

The NI Variable Manager is a lightweight, stand-alone component with which programs using the network variable API can broadcast live measurement data across the Internet to several remote clients concurrently. The NI Variable Manager simplifies network programming by automatically managing connections to clients. Broadcasting data with the NI Variable Manager requires three "actors" – a publisher, the Shared Variable Engine, and a subscriber. A publishing application uses the Network Variable API to write data to the server. A subscribing application uses the Network Variable API to read data from the server. Both the publishing and the subscribing applications are "clients" of the Shared Variable Engine. The three actors can reside on the same machine, but more often the three actors run on different machines. The ability to run the Shared Variable Engine on another machine improves performance and provides security by isolating network connections from your measurement application.

Explicitly Created Network Variables

To create and configure network variables explicitly, you use the stand-alone NI Variable Manager application. Select Start»Programs»National Instruments»Variable Manager»Variable Manager to access this application, which is included in the LabWindows/CVI installation. You would use this application to create new processes and variables, delete existing processes and variables, start and stop processes, create variables with specific data types or the variant data type, allow multiple writers or restrict write access to a single client, configure server buffering, and so on. For more information about creating network variables explicitly, refer to the Variable Manager Help, which you can access from the Variable Manager.

Implicitly Created Network Variables

You can implicitly create network variables in the system process: a new variable is created automatically when you connect to it, if the process name is system and the variable name you specify does not already exist in the system process. For example, \\localhost\system\test would implicitly create a variable called test in the system process on your local computer. If the variable already exists, then your program connects to the existing variable and does not create a new variable. An implicitly created variable is automatically deleted by the server when all of its clients have disconnected. Implicit variables have no concrete data type and can hold values of any type. They always have the single-writer restriction and their values are not buffered on the server, but their values can be buffered on the client. Implicit variables can be easily deployed because they are automatically created and deleted.

Applications Using Network Variables

Because network variables are a general-purpose programming tool for enhancing measurement applications, you can use it in a variety of different applications. The following section describe an example application.

Using Network Variables to Monitor Process Variables

Imagine a data acquisition board production factory that makes several different types of acquisition boards. Each type of board has its own production line, and each line has a computer that monitors the process variables. You are a systems engineer chosen to write a LabWindows/CVI application that continuously monitors each of the process variables. Your application writes the live data to the central office over the local network. A computer in the central office gathers data and displays a live summary by production line and by process variable so that factory managers have an up-to-date picture of how the factory performs.

Without network variables, you would have to write a TCP/IP server and client application to transfer the data from the factory floor to the central office. The server application would acquire the process data, flatten the data into a bit stream, and transfer the data to the server.

The server reads, unflattens, and displays the data. In addition to the code required to read information from the server, the client application must also contain the code required to manage multiple connections - one connection for each process line. Writing all the low-level TCP/IP code to handle such data transfers would add a significant amount of overhead to the development process.

With network variables, you can easily handle the network communication required to move data from the factory floor to the central office. In LabWindows/CVI, use the NVCreateBufferedSubscriber, NVCreateBufferedWriter, NVPutDatainBuffer and NVFinish functions to write and read process variable data. Because data is managed by the Shared Variable Engine, the central office application does not need to implement extra code to handle the additional connections of multiple production lines. It simply reads the data item for each line.

This example illustrates how to broadcast data over a local network. You could expand upon the acquisition board scenario by passing process control information from the central office back to the production lines. Because network communication can span Windows or real-time systems, your central office could be accessing diverse hardware and test systems around the world.

Communication between Real-Time Applications

The Shared Variable Engine can be accessed from NI LabVIEW, LabWindows/CVI, and Measurement Studio. With network variables in LabWindows/CVI and Measurement Studio for Visual Studio and shared variables in LabVIEW, you can easily perform cross-platform communication among several applications written in various languages.  The LabWindows/CVI Real-Time Module also expands the functionality of network variables. With LabWindows/CVI Real-Time, you can configure a network variable in conjunction with a thread-safe queue when handling data. Using thread-safe queues ensures that passing data between tasks or over the network does not add jitter to an application.

Additional Resources

LabWindows/CVI provides access to a wide array of technologies for creating distributed applications. The network variable introduced in LabWindows/CVI 8.1 is a major step forward in simplifying the programming necessary for such applications.

3 ratings | 4.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).