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

Document Type: Tutorial
NI Supported: Yes
Publish Date: Oct 15, 2007


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Calling LabVIEW VIs Interactively from DIAdem

4 ratings | 5.00 out of 5
Print

Overview

In this application note we will discuss how you can leverage the powerful analysis capabilities offered by LabVIEW interactively in DIAdem. In addition to extending the analysis capabilities of DIAdem, LabVIEW offers several very specific analysis functions such as pulse analysis, and advanced array functions that make it very easy to design sophisticated functions. The example program included in this application note allows to run VIs you have created in LabVIEW from within DIAdem.

Ways to Connect Between LabVIEW and DIAdem

The LabVIEW DIAdem Connectivity VIs are a free addition to LabVIEW which enable a user to read and write DIAdem Data Files, and to interact with DIAdem’s OLE interface. Through the OLE interface, users interact directly with DIAdem to read and write Data Channels. The VIs which use DIAdem’s OLE interface basically expose DIAdem’s ActiveX functions and allow the user to perform a wide range of operations on the DIAdem environment. DIAdem 9.x has a LabVIEW button which opens up an example VI that demonstrates how to use the connectivity VIs to pass data between LabVIEW and DIAdem. If you want total control over how your data is being passed between LabVIEW and DIAdem, this is probably the best method.

The LabVIEW VI connectivity tool for DIAdem makes it easy to quickly interface with any LabVIEW VI which has its inputs and outputs exposed through its connector pane. The advantage to using this method of interfacing with a LabVIEW VI is that no additional LabVIEW programming is needed if the terminal data types that you are interested in accessing are supported by the tool. The disadvantage is that data types which aren’t supported by the tool cannot be passed to or from the connectors of the VI. The rest of this application note will focus on how to use the LabVIEW connectivity tool in DIAdem, and will discuss certain limitations of the tool.

Click here to download the Tool for Calling LabVIEW VIs Interactively from DIAdem

Requirements and Installation Instructions the LabVIEW Connectivity Tool



Requirements
1) You must have a full version of LabVIEW on your machine.

2) You must have either DIAdem 8 or DIAdem 9 on the same machine.

Installation
1) Copy the attached Installer.zip file to your computer and extract the contents to any location.

2) Run the setup.exe file, which should be located in the directory that you extracted the contents of the Installer.zip file.

3) Take a look at the readme.txt file, which should be located in the 'docs' folder, for more detailed installation instructions.

Example: Interfacing with a LabVIEW VI using the LabVIEW Connectivity Tool



1) Open DIAdem and from the toolbar click on the DIAdem-AUTO button if you are in DIAdem 8, or the DIAdem-Script button if you are in DIAdem 9, to enter the Autosequence section of DIAdem.

2) Select File>>Open and browse to the location where the application was installed, which will be something like - c:\program files\LV DIAdem\ and open RunMe.vbs.

3) Press CTRL-F5 to run the Autosequence, or select Start VBS Autosequence from the Autosequence menu.

4) The Autosequence should have added a menu item to the menu bar called "Add LabVIEW VI".

5) Select "Add LabVIEW VI" from the menu.




6) Use the file browser to locate any VI on your machine. After selecting a VI, you should be able to see an image of its icon, and a list of all its terminals. If the terminal Type is ‘unknown’ then the datatype is not supported in DIAdem, and the terminals won’t be connected to DIAdem.




7) If everything looks OK, click on the Accept button.


8) The VI which you selected should now show up under "LabVIEW DynMenu" in DIAdem.


9) Select the VI from LabVIEW DynMenu to send data from DIAdem to the VI. You will see an interactive dialog that will enable you to pick the channels that you want to send to the VI’s input terminals, and which channels you want to return the data back into.

You can determine whether or not to view the VI’s front panel when it is executed. This is necessary if the VI requires user intervention during its execution.

Simply click on the cell for any valid input terminal in order to change the channel or data that is sent to the VI. If an input terminal is of a datatype that is not supported by DIAdem, such as a cluster, then that cell will be greyed out.

You may change the name of the channel that any valid output terminal gets written into by clicking on the cell in the Output tab. DIAdem 9 automatically checks the output channel names against existing channels in a particular group to make sure that an already existing channel doesn’t get over-written. In DIAdem 8, you must be careful not to overwrite an existing channel name.

10) After you have configured the data for the input and output terminals of the VI, click OK. The VI will execute using that data that you have passed it, and will return data from its output terminals back into the selected DIAdem channels when it is finished. No data will be returned to DIAdem until the VI is completely finished, so if the VI has a user interface which expects the user to interact with it before finishing, then you must locate the window for the VI and interact with it. Once the data has been saved into a channel back in DIAdem, you can use the data from the new channel just like any other channel.

How the Tool Works



This tool uses ActiveX to automate and transfer data between the LabVIEW and DIAdem environments.

Adding the LabVIEW DynMenu is done through the RunMe.vbs script. The initial dialog, which is called from the Add LabVIEW VI menu option, is basically a VI that is called from the AddMenuEntry.VBS script. The VI was written in LabVIEW and uses LabVIEW’s VI server functionality to gain information about the VI that the user chooses to interact with through DIAdem. The VI gathers all necessary information about the connector pane, including the name and datatype for each input and output terminal, whether or not the terminal connections are required or optional, and an image of the icon. This VI also returns the path information for the target VI, and then converts all of this information into VBScript variables that are appended to the top of a pre-made VBScript template file – ‘template_script.vbs’. The final product is a VBScript file, which is saved under the menu folder, that can be executed from within DIAdem that targets the selected VI and allows the user to send and receive DIAdem data through the connector pane of the VI.

The resulting script that is added to LabVIEW DynMenu has a couple different parts to it. The dialog that the script loads was created using DIAdem’s Dialog Editor. The file was saved as Settings.sud under the menu directory, and basically takes all of global DIAdem data that was saved at the top of the main script and passes that data to the dialog.

After a user has made their input and output selections from the dialog, the rest of the script performs the actions of opening the LabVIEW VI; sending the selected data from DIAdem to LabVIEW; then returning data from LabVIEW back to DIAdem. All of the LabVIEW interactions are done through LabVIEW’s activex server. Formatting DIAdem channels so that they can be passed to LabVIEW involved some functionality that DIAdem lacked. DIAdem channels are stored in memory as a 2D array with one column of data, so formatting the DIAdem data into data that would make sense to LabVIEW required the use of various LabVIEW functions. For example, to send a single DIAdem channel to a 1D array LabVIEW terminal, the DIAdem channel is first sent to a LabVIEW VI which takes a 2D array as its input, and returns only the first column as a 1D array. Similar tasks were performed for most other LabVIEW datatypes. After the DIAdem data is formatted properly, it can be sent seamlessly to LabVIEW’s activex ‘Call’ function.

After the VI has been executed, the data from the VI is returned back to DIAdem. The rest of the main script formats the data and uses a combination of internal DIAdem functions, and DIAdem OLE functions to create the DIAdem channels and save the data.

Troubleshooting



Problem: You get an error similar to the following:



Solution: Find DIAdemLabVIEW.exe and run it once, then close it. This will register the activex server for DIAdem.


Problem: Getting an error when trying to run a VI claiming that it can’t load the MSflexgrid.
Solution: This means you must register the msflxgrd.ocx file located in the tools main directory. The installer for the tool will attempt to register this activex object automatically, but if you need to register the object manually o to the command prompt and use the "regsvr32" command. The syntax for the command is (ignoring the quotes): regsvr32 “path to msflexgrd.ocx”

Problem: The tool isn’t creating any channels in DIAdem after running a VI, although everything else seems to be executing normally.
Solution: It is possible that a registry entry is not set properly for DIAdem; you should call National Instruments support for assistance with this issue.

Problem: Large text arrays seem to copy very slowly in DIAdem 9
Solution: This is simply a limitation with DIAdem – try using numeric array whenever possible for large amounts of data.

Problem: How can I send arbitrary channels of data as a single 2D array to LabVIEW?
Solution: Once again, this is just a limitation of DIAdem. DIAdem can only format continuous channels into a 2D array, so you will need to manually change the numeric value of your channels if you want them to be continuous.
4 ratings | 5.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/).