Applies To:
  • CitectSCADA
  • CitectHMI

Summary:
Under certain circumstances the behaviour of TrnGetTable cicode function under V5.31+ may be different to that experienced in earlier versions. For example, the statement:

TrnGetTable("TAG", TimeCurrent()-30, 180, 1, 0)...

Would have returned the average of non gated trend values for the 180 seconds up until 30 seconds ago.

 

Solution:
Under Version 5.31 or above, if there were any gated values in the period requested, the result would be zero. If mode 1 was chosen then the result would be the value for <Gated>

If you wish to get the average for an interval, then you should take the following into consideration.

1. The Citect V5.31+ trend system does have built in averaging, however to ensure that performance is not compromised by poorly written code, or large or long trend data requests, the algorithm will only average up to 300 raw trend points per averaged point. You should therefore choose your periods etc carefully to ensure that you are not exceeding this value if you require accurate averages.

2. It appears that if there is a gated or invalid value in the range over which you require the average then the result will also be gated or invalid. If you choose mode 0, the result will be 0.

It is therefore suggested that the trend averaging be used in conjunction with some other code to produce a more accurate average thus:

Real rTrendTable[2880];

Real rAverage;

TrnGetTable(sTagName, TimeCurrent() - 30, 30, 2880, rTrendTable[0], 1);

This will grab the trend table with 30 second resolution over one day in to a large table and grab any 30 second intervals with gated values in them will sho as the entire 30 second interval being gated.

rAverage = TableMath(rTrendTable,2880,2,1);

This will ignore gated values, so that they will not be counted in the average at all.

The result will be close to the average. If you require greater accuracy, you will need to increase the size of the table and reduce the period. The maximum size of the table is 15,359 elements.

See also KB Articles Q2489, Q1128

 

Keywords:
 

Attachments