Calling a LabVIEW SubVI with DIAdem

Publish Date: Nov 09, 2011 | 3 Ratings | 4.67 out of 5 | Print | Submit your review

Overview

DIAdem is a flexible software tool for managing, mining, inspecting, analyzing, and reporting measurement and simulation data. DIAdem is optimized to work with large data sets and can be customized to read and work with any file type. LabVIEW is the ultimate system design software that has the tools you need to create measurement and control applications to collect and save data to file. While each program has its strengths, combined provide an unparalleled platform for collecting and analyzing data.

• DIAdem has the capacity to analyze 2.1 billion samples/channel
• Expand the signal processing capabilities of DIAdem by utilizing advanced signal processing and math VIs available in LabVIEW
• Develop custom IP in LabVIEW for analyzing data and run the custom analysis IP from DIAdem
• Reduce the amount of DIAdem scripting you write and call the functionality required from LabVIEW
• Pass data from DIAdem to LabVIEW and use many of the connectivity toolkits to publish data via web service, TCP, etc.
• Interact with custom user interfaces developed in LabVIEW from DIAdem

Table of Contents

  1. Implementation Overview
  2. Step-by-Step Tutorial
  3. Preparing a LabVIEW VI to be Called in DIAdem
  4. Building a Source Distribution
  5. Writing the DIAdem SCRIPT to Call LabVIEW
  6. Caveats

1. Implementation Overview

You can create any custom algorithm in the LabVIEW environment and use a script created in DIAdem to call and run the VI created. To do this, you first develop the algorithm in a LabVIEW VI and prepare the VI to be called as a subVI. You then build a source distribution before calling the function from a DIAdem script. The remainder of this paper is dedicated to walking you through the process and making you aware of the few caveats associated with calling a LabVIEW VI from DIAdem.  There is a video that demonstrates the process and also a step-by-step tutorial. All files used for the video and step-by-step tutorial are available at the bottom of the article. 

Back to Top

2. Step-by-Step Tutorial

In this tutorial, you will be creating an application that finds the least common multiple of two numbers and returns the results; though this could be quickly implemented in DIAdem, this simple example could be easily exchanged with advanced or previously developed LabVIEW IP .This video shows how to implement the steps to create and call a LabVIEW subVI from a DIAdem script. For more detailed information about the implemenation, refer to the corresponding section below. 

Back to Top

3. Preparing a LabVIEW VI to be Called in DIAdem

In order for DIAdem to communicate with LabVIEW, you must create a subVI and define the inputs and outputs. In this section you will walk through the process of creating an algorithm from scratch and preparing the VI to be called from the DIAdem script you will write in a later section of the tutorial.

  1. Launch LabVIEW and take note of the version that you are developing your algorithm in. If you are unsure you can navigate to Help » About LabVIEW… to identify the version number. You will need the version number to tell DIAdem which LabVIEW Run-Time Engine to use to call your VI.

  1. From the Getting Started Screen open an Empty Project.

  1. Create a new VI by right-clicking on My Computer and selecting New » VI.

  1. On the Front Panel, right-click on the gray area to bring up the Controls Palette. Go to the Numeric Palette and place two numeric controls and one numeric indicator on the Front Panel.  You will be sending inputs and reading outputs from this VI using the labels of the controls and indicators. Rename the controls to “Input1” and “Input2” and the indicator to “Output.”

Note: Be sure to rename any controls and indicators you use to have meaningful names that you will immediately be able to identify in a script. DIAdem will use these names to pass and receive data from the LabVIEW VI.

  1. Assign the controls and indicators to the terminals in the connector pane. Click on a terminal in the connector pane and then select an input or an output.

Note:  The reason DIAdem is able to communicate with a LabVIEW VI is the setup of the connector pane. Assigning the inputs and outputs to terminals of the connector pane sets up a communication method to pass data between LabVIEW and DIAdem.

  1. Switch to the Block Diagram. You can go to Window » Show Block Diagram or hit Ctrl+E.
  2. Place the LCM.vi on the block diagram. You can use any of the search functions to find this VI or you can go to the Functions palette and navigate to Mathematics » Elementary & Special Functions » Discrete Math.
  3. Wire up Input1 and Input2 to the x and y input terminals of LCM.vi and Output to the lcm(x,y) output terminal of LCM.vi.

  1. Save the VI and the project to a folder. Take note of the folder you saved the project and VI to as there are other files that must be saved to this location as well. In this example the path to my folder is C:\Users\<…>\Desktop\DIAdem

Back to Top

4. Building a Source Distribution

To call the VI that was just saved in LabVIEW, it needs to be saved in such a way that the LabVIEW Run-Time Engine can find all associated files necessary to run the VI. A source distribution is a way to package all of the VIs and subVIs used in the program and points the LabVIEW Run-Time Engine to your VI.

  1. In the project, right-click on Build Specifications » New » Source Distribution.

  1. On the Information page, change the Destination directory to point to the project folder and specify that this source distribution will be saved to a builds folder.

  1. Under the Category section select Source Files. You should see the VI you saved listed under My Computer. Click on the VI under the Project Files section and then click on the Blue Arrow pointing right so that the VI is listed under the Always Included section.

  1. Go to the Additional Exclusions tab and deselect “Exclude files from vi.lib,” “Exclude files from instr.lib,” and “Exclude files from user.lib.”

Note:  By default a source distribution is configured to not include the standard VIs that ship with LabVIEW to reduce the size of the source distribution. In order for the LabVIEW Run-Time Engine to properly point to these VIs from a script, you must manually include these VIs in your source distribution build.  

  1. Build the Source Distribution. You are now ready to call your VI from DIAdem.

Back to Top

5. Writing the DIAdem SCRIPT to Call LabVIEW

DIAdem SCRIPT uses a built-in VBScript host so you can create everything from a simple sequence of analysis functions to complex, interactive reporting solutions. DIAdem SCRIPT combines the power of DIAdem for managing, analyzing, and reporting test data with the flexible, easy-to-learn Windows scripting language. We will use this to create a script that calls the LabVIEW Run-Time Engine (LVRTE) and run the custom VI that was developed. The commands that you will need to use are:

 Command  Description
 LVRuntime.Init  “Version”  Initializes the version of the LVRTE you specify
 LVRuntime.LoadVI (Path)  Loads the VI to be called from the path you specify
 VI.SetControlValue "Control Name", Value  Assigns input(s) to the VI being called
 VI.Run  Executes the VI
 VI.GetControlValue ("Output Name")         Receives output(s) from the VI
 LVRuntime.DeInit  Shuts down the LVRTE
  1. Open DIAdem and go to the SCRIPT workspace.

  1. Save the script to the project folder.
  2. Use the following script to call the LabVIEW VI just created.

Dim PathtoVI, VI, Answer   'Set up variables
PathtoVI =  CurrentScriptPath + "LeastCommonMultiple.vi"

LVRuntime.Init "11.0"     
Set VI = LVRuntime.LoadVI (PathtoVI)
VI.SetControlValue "Input1", 15  
VI.SetControlValue "Input2", 18  
VI.Run False 

Answer = VI.GetControlValue ("Output")  
Call msgboxdisp (Answer)   'Shows output in a dialog box
LVRuntime.DeInit    

  1. Run the script by clicking on the green arrow and you’re done!

Back to Top

6. Caveats

While you can use many of the features and functions in LabVIEW that are not available in DIAdem, there are a few things that you should avoid.

Clusters are a special LabVIEW datatype that groups data elements of mixed type into a single control or indicator. Clusters are unique to LabVIEW and the scripting done in DIAdem is based off Visual Basic. If you have a cluster in a VI that you would like to call from DIAdem, separate the cluster into its individual elements and then connect each item to the connector pane of the VI.

Another data type that is based off of a cluster is a waveform. A waveform bundles data along with a timestamp. It is great to use this datatype in LabVIEW because it provides valuable information about when the data was acquired and also allows for multiple data channels to reference the same time channel. Instead of passing large waveforms between a DIAdem script and a LabVIEW VI, it is recommended to access the data using File I/O instead.

The last thing to watch out for is that any VI you create that uses a subVI, including subVIs that ship with LabVIEW, a source distribution must be created and saved to the folder where the VI is saved. A source distribution is a collection of all of the subVIs used throughout the program that was developed. Without creating a source distribution the LabVIEW Run-Time Engine will not be able to locate all the references used throughout the program and the script will error out when the script attempts to load the VI as seen in the image below.

Back to Top

Bookmark & Share


Downloads

Attachments:

lcm2011.zip


Ratings

Rate this document

Answered Your Question?
Yes No

Submit