|Download Help (Windows Only)|
May 7, 2019, 375857B-01
|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:
You can implicitly or explicitly create and configure network 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.
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.
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|
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.
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.
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.
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.