Network Variable Feature Overview

Measurement Studio 2019 Help

Edition Date: May 2019

Part Number: 375857B-01

»View Product Info
Download Help (Windows Only)

May 7, 2019, 375857B-01

Note Note   This topic applies to the following editions: Enterprise, Professional.

The Measurement Studio Network Variable .NET class library includes three namespaces: NetworkVariable, NetworkVariable.WindowsForms, and NetworkVariable.WebForms. The NetworkVariable namespace includes core network variable functionality, such as read and write functionality. The NetworkVariable.WindowsForms and NetworkVariable.WebForms namespaces include functionality for binding network variables to Windows Forms and Web Forms controls.

You use the Network Variable class library to transfer live measurement data between applications over a network. You can use network variables to exchange different types of data between Measurement Studio, LabVIEW, LabWindows/CVI, and other applications that support NI-Publish Subscribe Protocol (psp:) and OLE for Process Control (opc:) servers. Exchanging data between Measurement Studio applications and OPC servers requires LabVIEW DSC Run-Time System.

This library supersedes DataSocket because NetworkVariable has better performance and scalability. Refer to Using the Network Variable .NET Library to Exchange Data with LabVIEW and LabWindows/CVI for information on the benefits of using network variables in these environments.

The Network Variable class library writes and reads from variables that live on the server. To reference a network variable, you must pass a string to the constructor of the reader or writer that represents the location of the variable. The format of the location string is similar to the format of network file share names. The format is not case-sensitive. For example, you might write \\machine\myprocess\item on Windows. In this example, machine is the machine name, the IP address or Fully Qualified Domain name of the server machine that is hosting the variable; myprocess contains network variable folders or variables; and item is the name of the network variable. In the example, myprocess refers to a network variable process. You can organize your variables into separate processes. The following list shows more valid location strings:

  • \\localhost\testlib\double
  • \\localhost\process\test
  • \\testmachine\system\doublearray

You can implicitly or explicitly create and configure network variables.

Implicitly Creating Variables

You can implicitly create network variables by connecting to a variable in the reserved process System. Implicitly created variables are created automatically when a writer connects to them. For example, if you use a NetworkVariableWriter<TValue> to connect to a network variable with the location \\localhost\System\MyVariable, the variable is automatically created if it does not already exist. Implicitly created network variables are automatically deleted by the server when all network variable clients have disconnected. Implicit variables are always of type Object and can hold any value. Implicit variables only allow connections from one writer at a time; any attempt to connect with a second writer throws a NetworkVariableException. Implicit variables cannot be buffered on the server, but NetworkVariableBufferedWriter<TValue> or NetworkVariableBufferedSubscriber<TValue> can perform client-side buffering of an implicit variable.

Explicitly Creating Variables

You can explicitly create a variable programmatically with the network variable API or by using the stand-alone Distributed System Manager application. By manually creating variables, you have more options, such as server buffering and specifying the type of the variable. An explicitly configured variable exists even when no active connections are made to the variable.

  • Programmatically Creating Variables: You can programmatically create variables using the following classes in the network variable API: ServerProcess, ServerProcessInfo, ServerVariable, and ServerVariableInfo. Refer to Explicitly Creating Network Variables for more information.
  • Creating Variables with NI Distributed System Manager: Refer to Creating, Modifying, or Deleting Shared or Network Variables topic in the NI Distributed System Manager Help for information on how to create an explicit variable with the Distributed System Manager. Select Start»All Programs»National Instruments»Distributed System Manager to launch the application. In Distributed System Manager, select Help»System Manager Overview to access the help.

Reader and Writer Classes

The following table lists Network Variable .NET class library readers and writers and their use cases.

Network Variable .NET Class Library Reader or Writer On-Demand1 Scalable2
NetworkVariableReader<TValue> X  
NetworkVariableBufferedSubscriber<TValue>   X
NetworkVariableSubscriber<TValue>   X
NetworkVariableWriter<TValue> X  
NetworkVariableBufferedWriter<TValue>   X

Reader and Writer Classes Defined

The Network Variable .NET class library includes the following five reader/writer classes:
  • NetworkVariableReader<TValue>—This class reads network variable on demand. The server does not automatically send data to your program. Instead, you call ReadData to read the variable on the server. ReadData blocks until a value can be read from the network. ReadDataAsync does not block. When using ReadDataAsync, use the ReadDataCompleted event to obtain the read value.
  • NetworkVariableBufferedSubscriber<TValue>—This class reads network variable data from a client side buffer. The server automatically sends new data to your program where the item is buffered. When the server pushes data to NetworkVariableBufferedSubscriber<TValue>, the data is put into the client side buffer. Use this model if you are reading values slower than they are being pushed from the server and you do not want to lose data. Use ReadData to get the next value in the buffer. You can use ItemCapacity to increase or decrease the size of the client side buffer. Use ItemCount to obtain the number of current items in the buffer.
  • NetworkVariableSubscriber<TValue>—This class subscribes to network variable data and receive update notifications. The server automatically sends new data to your program. You can use DataUpdated for notification when new data is available.
  • NetworkVariableWriter<TValue>—This class writes network variable data on demand. You use this class when the value must be written to the server immediately. WriteValue or WriteData blocks until the value is written to the server. WriteValueAsync and WriteDataAsync do not block. When working with these methods, use the WriteCompleted event to see if the async call succeeded. Refer to Deciding When To Use NetworkVariableWriter or NetworkVariableBufferedWriter for more information.
  • NetworkVariableBufferedWriter<TValue>—This class writes network variable data to a client side buffer. You use this class to write values quickly, and you do not want to block or lose data. Values accumulate in the client side buffer until the client decides to push the values to the server. Pushing values in groups reduces network traffic and increases performance. You can use ItemCapacity to increase or decrease the size of the client side buffer. Use ItemCount to obtain the number of current items in the buffer.

Network Variable Flushing Behavior

All network Variable readers and writers maintain data in buffers that are flushed periodically. You can use the flushing behavior to help optimize performance. For example, using a NetworkVariableBufferedWriter<TValue> instead of a NetworkVariableWriter<TValue> can make writing in a loop faster.

Browsing Network Variables

Network Variable Browser Dialog

The Network Variable .NET class library includes a NetworkVariableBrowserDialog component. You access NetworkVariableBrowserDialog component from the Toolbox in Visual Studio, and you use the component to browse created network variables on the local subnet. NetworkVariableBrowserDialog is similar in functionality to the FolderBrowserDialog component in the .NET Framework. Using the browser dialog, you can select a particular network variable location. You can add a machine that is not on the subnet. To add a machine, right-click Network Neighborhood and type in the machine name. You can also remove a machine. To remove a machine, right-click the machine and select Remove.

Network Variable Browse API

You can use the Browser class to browse available network variables. To find network variables, create an instance of the Browser class and use GetSubitems or GetSubitemsAsync mehods. The Browser class can access all machines on the local subnet; use the RegisterMachine to add machines that are not in the local subnet. Refer to the Browser class library documentation for more information.

Supported Data Types

The NetworkVariable API uses generics to strongly type the API. You must specify a type when you create a reader or writer. Refer to NetworkVariableReader<TValue>, NetworkVariableBufferedSubscriber<TValue>, NetworkVariableSubscriber<TValue>, NetworkVariableWriter<TValue>, or NetworkVariableBufferedWriter<TValue> for information on what types are supported.

If a type is read from the network that does not match the type specified in the reader, an exception is thrown. If the type being read from the network is unknown or might change, specify Object as the type when creating the reader.

Complex types may be written using .NET serialization, but are only supported when communicating from one instance of .NET to another instance of .NET. LabVIEW and LabWindows/CVI do not have a way of understanding complex types, such as classes. To write a complex type to a network variable, serialize the object into a byte[] and then write the byte[] to the network variable. To read a complex type from a network variable, read the byte[] and deserialize it back to the Object.

Binding

You can use the WindowsForms.NetworkVariableDataSource control to transfer live data between network variables and Windows Forms, and you use WebForms.NetworkVariableDataSource control to transfer live data between network variables and Web Forms.

1 Use these classes to make synchronous (blocking) calls across the network that do not return until the read or write operation completes and the server has been updated.
2 Use these classes for applications that require communication with a large number of network variables and to transfer data at high speeds without adversely affecting network traffic or application performance.

WAS THIS ARTICLE HELPFUL?

Not Helpful