Example Code

Calculate Channel Average and Count Combined Events Using VBScript

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • Diadem

    Operating System

  • Windows

Code and Documents

Attachment

Description

 

This script will show a general flow of atuomating data analysis in DIAdem. The major tasks are: 

 

  • Find the Example.tdm file from myDataFinder and load it to the Data Portal.
  • Calculate the average value of the Speed channel. Displays to the user.
  • Count the number of samples when the Speed is above 40m/s and the RPM is above 2000 RPM.

 

Those types of calculations are common in automotive applications where you log a set of data from the vehicle and you want to perform some process on DIAdem. One important aspect of that automation is that it won't store any results in Data Portal, keeping it only with the data acquire.

 

The scripts contains 4 functions that you can easily modify to meet your needs:

  • findFile() - Add the name and the Data Plugin name of the file you want to load. You can also extend its functionality to add more search criterias by adding more lines of Call oQueryForm.Conditions.Add
  • loadFile()- It will load the files resulting from the search on findFile(). You can add a few more lines of code to select an specific item from the list of results.
  • calculateAvrgSpeed() - This function will run an equation from the calculator. It calculates only the average speed of the [1]/Speed channel, but you can modify it to get whatever channel you want. You can also call the calculate function to perform any calculations the DIAdem calculator can perform.
  • getEventCount() - this function was created from the Channel Functions>>Event Search. In order to modify it, go to the ANALISYS tab, and open the Event Search function. On the dialog box, configure it as you want and then press the Ctrl+Shift+C key combination and paste it to any script file. It will paste the script that reproduces your settings from the dialog box as well as the code to call the Event Search function.

As a matter of simplicity, message boxes are displaying the results of each analisys. Feel free to add code to include that information anywhere your application needs.

How to Use

This script is ready to run. Just open DIAdem, go to the SCRIPT tab. Load the "AutomateDataAnalysis.VBS" and then press the Run button (or F5 on your keyboard)

Additional Information

For the begginer users of DIAdem Scripts in VBS, you can see a simple practical example of how to automate data load and process. Also, you can see how to use functions and subroutines to keep the main code clean, easy to read, and easy to extend or modify.

Related Links

Felipe Flores
Technical Support Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors