Applies To:
  • CitectSCADA 3.xx, 4.xx, 5.xx

Summary:
I want Citect to be able to log a value and to report what the minimum, maximum and the average value was over a period of time. 

Solution:
To get Citect to log data so that you can calculate the Min, Max and Average values of a Tag over a period of time, set up a "Trend Tag" first. Be sure to set the sample period to the longest time possible.

Next set up a report as per the example;

Example of Min, Max and Average values of a tag in a report.

   {Time(1) } {Date(2) }
{cicode}
   GetTrendFileData("CPU", 1);
   PrintLn("Max CPU usage is: "+ReportMath(1));
   PrintLn("Min CPU usage is: "+ReportMath(0));
   PrintLn("Avg CPU usage is: "+ReportMath(2));
{end}
   End of Report
{FF}

Then use the following Cicode functions that the report needs to calculate the Min, Max and Average values, see below. The time period covered will be from the current time back over the number of hours specified when calling the GetTrendFileData() from the report.

Example of GetTrendFileData() & ReportMath() Cicode Functions called by the report.

/*
** The array rFileData[] set to the max size possible,
** this example will cater for about 24 hours worth of data
** (if trend tag is set to a minimum of 6 sec sample period).
*/
Real rFileData[15000];
INT iSamples;

/*
** Function Name: GetTrendFileData ()
** Called by : Report
** Inputs: The trend Tag Name, The number of hours of data from the current time.
**
*/
FUNCTION
GetTrendFileData(STRING sTrendTag, INT iHours)
   STRING sPeriod = TrnInfo(sTrendTag, 2);
   iSamples = (3600 * iHours)/StrToInt(sPeriod);
   ErrSet(1);
   TrnGetTable(sTrendTag, 0, 0, iSamples, rFileData[0], 1);
   ErrSet(0);
END

/*
** Function Name: ReportMath()
** Called by : Report
** Returns: String equal to either Min, Max or Avg value as determined by the mode.
*/
STRING
FUNCTION
ReportMath(INT iMode)
   REAL rValue;
   rValue = TableMath(rFileData, iSamples, iMode, 1);
   return RealToStr(rvalue, 6, 2);
END

 

Keywords:
 

Attachments