Adding Network Variables to a Measurement Studio Windows Application

Publish Date: Apr 04, 2018 | 0 Ratings | 0.00 out of 5 | Print | Submit your review

Overview

You can use this tutorial to add network variables to an exisitng Measurement Studio Windows application.

Table of Contents

  1. Introduction
  2. Before You Begin
  3. Explicitly Creating Network Variables
  4. Running the Signal Filtering Windows Application
  5. Adding Network Variables to the Signal Filtering Windows Application
  6. Related Resources

1. Introduction

Measurement Studio includes user interface controls for Windows development, such as the waveform graph, knob, gauge, tank, LED, switch, and other controls. Measurement Studio 8.1 and later includes the network variable application programming interface (API). With network variables, you can perform cross-platform communication among several Windows or real-time applications. You can use the network variable class library to send data to Windows applications, as well as remotely monitor and control distributed applications.

This tutorial is designed to help you learn how to modify a pre-existing Windows application to use network variables. This tutorial will take you through the following steps:

  • Explicitly create network variables—You will use Distributed System Manager to create network variables on your computer.
  • Add network variables to the Signal Filtering Windows Forms application—Using the Measurement Studio Network VariableDataSource control, you will write the application output values to network variables. This tutorial uses the Signal Filtering Windows application attached to this document.

Back to Top

2. Before You Begin

The following components are required to complete this tutorial:

  • Microsoft Visual Studio 2005 or later
  • Measurement Studio 8.1 or later (Professional or Enterprise package)

Back to Top

3. Explicitly Creating Network Variables

  1. Select Start»All Programs»National Instruments»Distributed System Manager.
  2. Right-click on localhost and select Add Process.
  3. Name the process Signal Filtering and click OK.
  4. Right-click on Signal Filtering and select Add Variable.

 

  1. Name the variable Cutoff, select Double as the Data Type , and click OK.

  1. Right-click on Signal Filtering and select Add Variable. Name the new variable OriginalSignal, select Array of Double for the Data Type, and click OK.
  2. Right-click on Signal Filtering and select Add Variable. Name the new variable FilteredSignal, select Array of Double for the Data Type, and click OK.
  3. Select File»Exit to close the Distributed System Manager.

Back to Top

4. Running the Signal Filtering Windows Application

The Signal Filtering application attached to this tutorial generates a noisy signal and displays it on a waveform graph. You can filter the signal by increasing the cutoff frequency; the filtered signal then displays on a waveform graph.

  1. Download the signalfiltering_csharp.zip or signalfiltering_vb.zip file, depending on which language you want to use.
  2. Select Start»All Programs»Microsoft Visual Studio 2005»Microsoft Visual Studio 2005.
  3. Select File»Open»Project/Solution. The Open Project dialog box launches.
  4. Browse to the Measurement Studio Signal Filtering application.
  5. Select the .sln file and click OK.
  6. Select Debug»Start Without Debugging to run the project.
  7. Change the value of the Cutoff Frequency slider control to reduce the noise displayed in the Filtered Signal waveform graph.  
  8. Close the application.

Back to Top

5. Adding Network Variables to the Signal Filtering Windows Application

 

  1. Select View»Designer.
    Note   The View»Designer menu option is available only when you have a file within the project open.  
  2. Expand the Measurement Studio group in the Toolbox.
  3. Drag and drop a NetworkVariableDataSource control onto the form. The NetworkVariableDataSource control is a data source control with functionality similar to ObjectDataSource and SqlDataSource in the .NET Framework. The NetworkVariableDataSource control encapsulates network variable functionality.

     
  4. Click the NetworkVariableDataSource1 smart tag and select Edit Bindings.

    Tip   
    To access the smart tag, left click on a control to select it and then left click on the arrow button in the upper right corner of the control.
  5. Click Add. You add a binding to create a connection with the underlying network variable, and you use the NetworkVariableBinding Collection Editor to configure the binding properties.
  6. Add the OriginalSignal network variable by setting the following options in the NetworkVariableBinding Collection Editor dialog box: select Read for BindingMode, type 0 for DefaultReadValue, and type Original Signal for Name.
        
  7.  For the Location, browse to the \\localhost\Signal Filtering\OriginalSignal in the Select Network Item dialog box. Click OK.

  8. Add the FilteredSignal network variable by setting the following options in the NetworkVariableBinding Collection Editor dialog box: select Read for BindingMode, type 0 for DefaultReadValue, and type Filtered Signal for Name.
  9. For the Location, browse to the \\localhost\Signal Filtering\FilteredSignal in the Select Network Item dialog box. Click OK.

  10.  

    Add the Cutoff network variable by setting the following options in the NetworkVariableBinding Collection Editor dialog box: select ReadWrite for BindingMode, type 0 for DefaultReadValue, and type Cutoff for Name.

  11. For the Location, browse to the \\localhost\Signal Filtering\Cutoff in the Select Network Item dialog box. Click OK.

    Note    Make sure the members of the NetworkVariableBinding Collection Editor are in the following order: 0-Originak Signal, 1-Filtered Signal, and 2-Cutoff. If the members are not in this order, use the arrow buttons in the NetworkVariableBinding Collection Editor to order them.

  12. Click OK to return to the NetworkVariableBinding Collection Editor dialog box.
  13. Select View»Code to view Form1.
  14. Add the following code to the beginning of the timer1_Tick method in Form1 to programmatically declare a NetworkVariableBufferedWriter to update the value of the OriginalSignal and the FilteredSignal network variables.

    [C#]
    String originalSignal_location =
    networkVariableDataSource1.Bindings[0].Location.ToString();


    NetworkVariableBufferedWriter<double[]> originalSignalBufferedWrite = new
    NetworkVariableBufferedWriter<double[]>(originalSignal_location);

    String filteredSignal_location =
    networkVariableDataSource1.Bindings[1].Location.ToString();
    NetworkVariableBufferedWriter<double[]> filteredSignalBufferedWrite = new
    NetworkVariableBufferedWriter<double[]>(filteredSignal_location);

    [VB.NET]
    Dim originalSignal_location As String
    originalSignal_location = NetworkVariableDataSource1.Bindings(0).Location.ToString()
    Dim originalSignalBufferedWrite As NetworkVariableBufferedWriter(Of Double())
    originalSignalBufferedWrite = New NetworkVariableBufferedWriter(Of Double())(originalSignal_location)

    Dim filteredSignal_location As String
    filteredSignal_location = NetworkVariableDataSource1.Bindings(1).Location.ToString()
    Dim filteredSignalBufferedWrite As NetworkVariableBufferedWriter(Of Double())
    filteredSignalBufferedWrite = New NetworkVariableBufferedWriter(Of Double())(filteredSignal_location)

  15. Add the following code to the end of the timer1_Tick method in Form1 to programmatically bind the network variables to the data that is being displayed on the Original Signal and Filtered Signal waveform graphs.

    [C#]
    originalSignalBufferedWrite.Connect();
    originalSignalBufferedWrite.WriteValue(originalData);
    filteredSignalBufferedWrite.Connect();
    filteredSignalBufferedWrite.WriteValue(originalData);

    [VB.NET]
    originalSignalBufferedWrite.Connect()
    originalSignalBufferedWrite.WriteValue(originalData)
    filteredSignalBufferedWrite.Connect()
    filteredSignalBufferedWrite.WriteValue(originalData)

  16. Select View»Designer to switch back to Form1.
  17. Right-click the Cutoff Frequency slide control and select Properties.
  18. Expand DataBindings in the Properties Window for Slide1. For the Value select Other Data Sources»Form1 List Instances»NetworkVariableDataSource1»Cutoff. This binds the Cutoff Frequency slide control to the network variable.

          

Now that the signal filtering application binds to network variables, you can create a Web application to monitor the Windows application. 

 

Back to Top

6. Related Resources

 

Back to Top

Bookmark & Share



Ratings

Rate this document

Answered Your Question?
Yes No

Submit