Applies To:
  • CitectSCADA 5.31

Summary:
The Trend History File format has changed in Citect version 5.31. There are now two different file formats (Storage Methods) that can be used:

- The "Scaled (2-byte samples)" Storage Method uses the same file Header structures as in previous versions of Citect, but some fields hold different data.

- The "Floating Point (8-byte samples)" Storage Method has some changes to the File Header structures as well as some fields holding different data.

 

Solution:
The trend history system has a master file for each trend. This master file manages the trend history data files. When a history file is filled, data will be written to another trend data file (pointed to by the master file).

Master File Structure

The master file (.HST) has a header followed by an array of history file information. The history files are ordered so that the most recent one is at the top.

MASTERHDR
HISTFILE most recent
HISTFILE
HISTFILE oldest

MASTERHDR structure

NAME SIZE DESCRIPTION
title 128 Title of the file (ASCII). It contains information, such as file version, type, start time and logging name.
ID 8 ID for Citect files. It is set to "CITECT".
type 2 Type of the Citect file. It is set to 0, which is FILE_TYPE_TREND.
version 2 Version number of the trends. (3 or 4 depending on the storage method of the Trend)
alignment 4 alignment for 16 bytes
Mode 4 Indicates the mode of the MASTER file. (For future use. Currently it is set to 0.)
History 2 Maximum Number of history files to be created. (not including AddOn)
nFiles 2 Number of history files currently created. (not including AddOn)
next 2 Next history file number. Internal use only, users MUST NOT use this entry to get the next history file.
AddOn 2 Shows the number of history files added onto the system through user functions. User can add old (backed up) history files to the system temporarily by using TrnAddHistory() and TrnDelHistory().
alignment 20 alignment for 16 bytes

NOTE 1: You have to read the whole master file to determine the sequence of history files.

Parts of the HISTFILE structure and Trend Data File are different, depending on the storage method. So here are the structures for the different Storage Methods.

Scaled (2-Byte samples) Storage Method

HISTFILE structure

NAME SIZE DESCRIPTION
Name 144 History file name.
BinHdr 96 History file binary header. See HISTBINHDR structure.

HISTBINHDR structure

NAME SIZE DESCRIPTION
ID 8 ID for Citect files. It is set to "CITECT".
type 2 Type of the Citect file. It is set to 0, which is FILE_TYPE_TREND.
version 2 Version number of the trends. (equal to 3 for this Storage Method)
StartEvNo 4 Starting Number for events in this history file. (Event Trends only.)
LogName 32 Name of the trend record that owns the history file.
Mode 4 Indicates the mode of the history file. (For future use. Currently it is set to 0.)
Area 2 The area that has access to the acquired data.
Priv 2 The access rights required to execute the command.
FileType 2 History File Type. Set to 0 for Periodic and Periodic_Event Trends. Set to 4 for Event Trends.
SamplePeriod 4 Sample period of logging (in milliseconds)
sEngUnits 8 Units of scales. (Set to the units of the trend record.)
Format 4 Format of scales. (Set to the format of the trend record.)
StartTime 4 The earliest time that a sample can have and be placed in this file, in seconds since 1970.
EndTime 4 For Periodic Trends the EndTime is always set to the latest possible sample time that can be put into this file. For Event Trends the EndTime is the time of the newest sample stored in the file (one less than the StartTime if there are no samples in the file). Stored as a number of seconds since 1970.
DataLength 4 Shows the number of data items. DataLength = (File Size - HeaderSize) / 2
FilePointer 4 The location of the newest sample in the file, in number of samples from the start of the data portion of the file.(Periodic Trends only).
EndEvNo 4 The event number of the next sample after the last one in this file. (Event Trends only)
alignment 2 for 16 bytes

Trend Data File structure - Periodic and Event Periodic Trends

HISTFILEHDR

data (2 bytes per data)

Trend Data File structure - Event Trends

HISTFILEHDR

data (SCALEDEVENTSAMPLE per sample)

SCALEDEVENTSAMPLE structure

Value 4 The value of the sample
Time 4 The time of the sample in seconds since 1970
Milliseconds 4 The milliseconds of the time of the sample

HISTFILEHDR structure

title 112 ASCII title of the file. It contains information, such as, file version, type, start time and logging name.
DefScale 16 default scales. See the structure of DEFAULTSCALES below.
BinHdr 96 Binary header for history files. See HISTBINHDR structure

DEFAULTSCALES structure

RawZero 4 (float)
RawFull 4 (float)
EngZero 4 (float)
EngFull 4 (float)

Floating Point (8-Byte samples) Storage Method

HISTFILE structure

NAME SIZE DESCRIPTION
Name 272 History file name.
BinHdr 160 History file binary header. See HISTBINHDR structure.

HISTBINHDR structure

NAME SIZE DESCRIPTION
ID 8 ID for Citect files. It is set to "CITECT".
type 2 Type of the Citect file. It is set to 0, which is FILE_TYPE_TREND.
version 2 Version number of the trends. (equal to 4 for this Storage Method)
StartEvNo 8 Starting Number for events in this history file. (Event Trends only.)
alignment_1 12 for 16 bytes
LogName 64 Name of the trend record that owns the history file.
Mode 4 Indicates the mode of the history file. (For future use. Currently it is set to 0.)
Area 2 The area that has access to the acquired data.
Priv 2 The access rights required to execute the command.
FileType 2 History File Type. Set to 0 for Periodic and Periodic_Event Trends. Set to 4 for Event Trends.
SamplePeriod 4 Sample period of logging (in milliseconds)
sEngUnits 8 Units of scales. (Set to the units of the trend record.)
Format 4 Format of scales. (Set to the format of the trend record.)
StartTime 8 The earliest time that a sample can have and be placed in this file. (in number of 100 nanosecond time units since 1st of January, 1601)
EndTime 8 For Periodic Trends the EndTime is always set to the latest possible sample time that can be put into this file. For Event Trends the EndTime is the time of the newest sample stored in the file (one less than the StartTime if there are no samples in the file). (in number of 100 nanosecond time units since 1st of January, 1601)
DataLength 4 Shows the number of data items. DataLength = (File Size - HeaderSize) / 8
FilePointer 4 The location of the newest sample in the file, in number of samples from the start of the data portion of the file.(Periodic Trends only).
EndEvNo 8 The event number of the next sample after the last one in this file. (Event Trends only)
alignment_2 6 for 16 bytes

Trend Data File structure - Periodic and Event Periodic Trends

HISTFILEHDR

data (8 bytes per data)

Trend Data File structure - Event Trends

HISTFILEHDR

data (FLOATEVENTSAMPLE per sample)

FLOATEVENTSAMPLE structure

Value 8 The value of the sample
Time 8 The time of the sample (in number of 100 nanosecond time units since 1st January, 1601)

HISTFILEHDR structure

title 112 ASCII title of the file. It contains information, such as, file version, type, start time and logging name.
DefScale 16 default scales. See the structure of DEFAULTSCALES below.
BinHdr 160 Binary header for history files. See HISTBINHDR structure

DEFAULTSCALES structure

RawZero 4 (float)
RawFull 4 (float)
EngZero 4 (float)
EngFull 4 (float)
 

Keywords:
 

Attachments