Applies To:
  • CitectSCADA x.x

Summary:
Can I rely on the date and time stamp of the trend file that Citect is currently writing to in order to determine which is the previous file it has just completed or must I use the trend file header information?

Solution:
Both methods can be used. Firstly, I will mention how the trend system uses the trend Master file to find out which trend history file it will write its acquired data to. Secondly, the validity of the method where time stamp of the trend files is used.

(1) The trend system uses the trend master file to determine which trend history file it has to write the acquired data to. The same trend master file is used to locate the trend file when the user requests the trend data.

The KB articles Q1334, "Trend History Master and Data Files Structure" and Q1859 (which superseded Q1334 fro versions later than 3.30) "Trend History Master and Data Files Structure Version > 3.3" explain the Master File and History File format.

The Trend Master file has the following format: (Please refer to above article for the structures)

MASTERHDR
HISTFILE   most recent
HISTFILE
HISTFILE
...
...                 oldest

HISTFILE structure has the name of the trend history file and HISTBINHDR structure that has the StartTime and EndTime of the trend file.

The trend system uses the method below while writing the trend data to the trend history file:

The most recent history file in the Master file is the active file that the trend system writes the trend data to. The StartTime of the active file shows the start time of the file, ie. the first time the data was written to this file, and the EndTime is 0 (ZERO). When the active file gets full, in other words when its predefined period in the Trend Tags form has elapsed then the EndTime of the active file is stamped and the file is pushed down the list in acyclic way as explained by means of an example below. Now, the new active file's StartTime will be a continuation to the previous file's EndTime, and its EndTime will be ZERO as long as it is the active file.

Example: A trend has 4 trend files with a name, TREND1 then the Master file TREND1.HST will have the following layout:

MASTERHDR
TREND1.000 (StartTime = start time, EndTime = 0, note that StartTime is ZERO until the first lot of data is written)
TREND1.003 (StartTime = 0, EndTime = 0)
TREND1.002 (StartTime = 0, EndTime = 0)
TREND1.001 (StartTime = 0, EndTime = 0)

When the active file, TREND1.000 is full then the Master file's layout will be:

MASTERHDR
TREND1.001 (StartTime = EndTime of TREND1.000 + Sample Period, EndTime = 0)
TREND1.000 (StartTime = start time, EndTime = end time)
TREND1.003 (StartTime = 0, EndTime = 0)
TREND1.002 (StartTime = 0, EndTime = 0)

Third time around the layout becomes:

MASTERHDR
TREND1.002
TREND1.001
TREND1.000
TREND1.003

To this end, the user can write an application in 'C' to read the Trend Master file to determine the order and start time and end time of the trend history files.

(2) Knowing the fact that the order of files in the Master file is with respect to the update time of the history files one can use date and time stamp of these files to determine the active and previous history files. This method does not require any application written at all, the Cicode user function FileGetTime may be used to find the date and time stamp of the trend history files.

 

Keywords:
 

Attachments