Skip to main content
InSource Solutions

TN IT122 Using the Wonderware StatFunc utility to capture statistical metrics within InTouch

insource logo large.jpg

 

Description

StatFunc is an additional function that can be added to a Wonderware InTouch application that allows you to capture statistical data. This tech note is intended as an introduction to the utility.

 

  • Author: Joseph Hefner
  • Published: 04/10/2015
  • Applies to: InTouch 9.5 or later

 

 

Details

 

The first step to using this tool is to download the attached Stat32.zip file and extract the contents of the file to the Intouch appliciation directory. The directory below is for a 64 bit Operating System.

 

Capture10.JPG

 

 

Next, Open WindowMaker and create the tags you will be using for the statistical analysis. In the example below, I created a tag called test1 and I created testAvg and testMax to hold the statistical information:

 

Capture4.JPG

 

Capture5.JPG

 

Capture6.JPG

 

Next, you will create a folder to contain the csv file that lists all of the tags that statistical information will be performed against. You can use up to 512 tags with this function. In the image below, I created a folder on the C drive called Stat and placed the Stattags.csv folder in this location. The Stattags file will contain the name of every tag you need statistics for. In my example, I have only created the one tag called test1.

 

Capture2.JPG

 

Capture3.JPG

 

 

The next step will be to modify the win.ini file to tell the OS where to look for the Stattags.csv file. This is done by going to Start \ Run and typing in win.ini and adding the InTouch application feature lines below:

 

Capture.JPG

 

Next, You will create a window to hold the information. In the image below I linked Test1, TestAverage, and TestMax to the value displays and I linked Test1 to the slider so that I can easily test a change in data:

 

Capture7.JPG

 

Next, I created a while showing script on the window to initiate the statistical sample collection and calculate the Average and Maximum values for the tag.

 

Capture9.JPG

 

Below is the script used in the While Showing script above:

 

StatSample(Test1.Name);

TestAverage = StatGetAverage(Test1.Name,TestTrigger);
TestMax = StatGetMax(Test1.Name,TestTrigger);

 

In this case, TestTrigger is another tag that was created in order to call the function but it is not being used to trigger the calculations in this example.

 

Finally, open WindowViewer and move the slider to see the average and maximum calculations adjust based on the statistical data:

 

Capture8.JPG

 

 

 

The information below is from the StatFunc help file and should be helpful if you are trying to get some statistical data beyond the maximum and average as described above.

 

 

 

Capture11.JPG

 

 

Functions Provided

These functions are provided to allow you to track a variety of statistical values for up to 512 InTouch tags.  The tag could be a real, integer, or even a discrete tag.  The statistics that can be tracked are the average, maximum, minimum, and standard deviation.  Functions are provided to trigger sampling and to reset the statistics.  Sampling and resetting can be performed on individual tags or on all tags currently being monitored.  The STATTAGS.CSV file is used to define which tags are to be monitored.

 

 

Setting Up the STATTAGS.CSV file

This file MUST exist and be present in your application directory for these functions to work properly.  Note that the application directory is not where the InTouch software itself is installed, but the application directory where you are creating your actual InTouch application.  The preferred method of creating this file is to use the wizard provided in this DLL.  To install the wizard, simply select /Special/Install Wizards from the Window Maker configuration dialog.  To use the wizard, select it from the toolbox/Wizard list.

The file is simply a text file with a list of the tags to be monitored, with one tag on each line of the file.  Should you choose to create it manually, be certain that all of the tag names are valid.  An example of this file would be as follows:

Sample STATTAGS.CSV File Follows:

TIC101PV
PIC212PV
TT102PV
PIC301PV
PIC301OUT

 


StatGetAverage

Usage : TagAverageValue = StatGetAverage(TagName, TriggerTag);

Example :TagAverageValue = StatGetAverage(TIC101PV.Name, DummyTag);

If using this function as an expression for a real-time trend link or an analog output link, the value will only be updated when the trigger tags value changes.  Two approaches are to either use an integer variable of your choosing that is periodically changed at some time interval, or to keep track of the current sample count (for one or all of the tags being monitored) in an integer tag each time you take a sample for one or all tags and use this tag as the trigger (recommended).

This function will then return the accumulated average value of the tag as a floating point value (real-type tag value).  Note that if no samples have been taken, this function will return zero (0.0).

 

StatGetMax

Usage : TagMaxValue = StatGetMax(TagName, TriggerTag);

Example :TagMaxValue = StatGetMax(TIC101PV.Name, DummyTag);

If using this function as an expression for a real-time trend link or an analog output link, the value will only be updated when the trigger tags value changes.  Two approaches are to either use an integer variable of your choosing that is periodically changed at some time interval, or to keep track of the current sample count (for one or all of the tags being monitored) in an integer tag each time you take a sample for one or all tags and use this tag as the trigger (recommended).

This function will then return the maximum value of the tag since the last reset as a floating point value (real-type tag value).  Note that if no samples have been taken, this function will return zero (0.0).

 

StatGetMin

Usage : TagMinValue = StatGetMin(TagName, TriggerTag);

Example :TagMinValue = StatGetMin(TIC101PV.Name, DummyTag);

If using this function as an expression for a real-time trend link or an analog output link, the value will only be updated when the trigger tags value changes.  Two approaches are to either use an integer variable of your choosing that is periodically changed at some time interval, or to keep track of the current sample count (for one or all of the tags being monitored) in an integer tag each time you take a sample for one or all tags and use this tag as the trigger (recommended).

 

StatGetStdDev

Usage : TagStdDevValue = StatGetStdDev(TagName, TriggerTag);

Example :TagStdDevValue = StatGetStdDev(TIC101PV.Name, DummyTag);

If using this function as an expression for a real-time trend link or an analog output link, the value will only be updated when the trigger tags value changes.  Two approaches are to either use an integer variable of your choosing that is periodically changed at some time interval, or to keep track of the current sample count (for one or all of the tags being monitored) in an integer tag each time you take a sample for one or all tags and use this tag as the trigger (recommended).

This function will then return the accumulated standard deviation value of the tag as a floating point value (real-type tag value).  Note that if no samples have been taken, this function will return zero (0.0).

 

StatGetSampleCount

Usage : CurrentSampleCount = StatGetSampleCount(TagName, TriggerTag);

Example :CurrentSampleCount = StatGetSampleCount(TIC101PV.Name, DummyTag);

If using this function as an expression for a real-time trend link or an analog output link, the value will only be updated when the trigger tags value changes.  Two approaches are to either use an integer variable of your choosing that is periodically changed at some time interval, or to keep track of the current sample count (for one or all of the tags being monitored) in an integer tag each time you take a sample for one or all tags and use this tag as the trigger (recommended).

This function will then return the accumulated average value of the tag as an integer value.  Note that if no samples have been taken, this function will return zero (0).

 

StatGetSumXSquared

Usage : TagSumXSquared = StatGetSumXSquared(TagName, TriggerTag);

Example :TagSumXSquared = StatGetStdDev(TIC101PV.Name, DummyTag);

If using this function as an expression for a real-time trend link or an analog output link, the value will only be updated when the trigger tags value changes.  Two approaches are to either use an integer variable of your choosing that is periodically changed at some time interval, or to keep track of the current sample count (for one or all of the tags being monitored) in an integer tag each time you take a sample for one or all tags and use this tag as the trigger (recommended).

This function will then return the accumulated sum of the squared sample value (SUM(X2)) of the tag as a floating point value (real-type tag value).  Note that if no samples have been taken, this function will return zero (0.0).

 


StatReset

Usage : StatReset(TagName);

Example :StatReset(TIC101PV.Name);

This function will reset the statistics for the specified tag name.  The tag name can be passed as a string value, as a message tag, or as the .name field of a specific tag (recommended).

 

StatResetAll

Usage : StatResetAll();

Example :StatResetAll();

This function will reset the statistics for all tags being monitored.

 

StatSample

Usage : StatSample(TagName);

Example :StatSample(TIC101PV.Name);

This function will take a sample for the specified tag name by reading its current value from the InTouch real-time database.  The tag name can be passed as a string value, as a message tag, or as the .name field of a specific tag (recommended).

 

StatSampleAll

Usage : StatSampleAll();

Example :StatSampleAll();

This function will take a sample for each of the tags currently being monitored by reading the current values from the InTouch real-time database.