Geo SCADA Expert

Internal points provide a mechanism that can be used to add historic data into the system. These methods can be called using the automation interface or by writing some Structured Text Logic.

The basis of the code outlined below used two internal point properties named PresetTimestamp and PresetQuality. PresetTimestamp stores the timestamp (in UTC format) where the new data record will be added. PresetQuality stores the quality flag that will be associated with the new data record.

To add the historic record, set the PresetTimestamp and PresetQuality as required and set the new value for this record into the field CurrentValue for analog points or CurrentState for digital points. This will then add the record into the historic database with the correct timestamp and quality flag.

The structured text program below shows an example of this mechanism by writing a historic record into the database 14 days before the current time.

PROGRAM HistoricDemo
VAR
       (*
       The order of these variables is important, ensure that
       the time and qualities variables are defined BEFORE the actual
       value as when the program exits, they are written to in the
       order they are defined here. They can be used in any order in
       the code however.
       *)

       (* These two have to be %Q / write-only variables *)
       AnalogTime AT %Q(.Analog.PresetTimestamp) : DATE_AND_TIME;
       AnalogQuality AT %Q(.Analog.PresetQuality) : INT;

       (* This can be of any declaration type *)
       Analog AT %M(.Analog.CurrentValue) : INT;
END_VAR


(* Use RETAIN keyword so different value written each execution *)
VAR RETAIN
       Count : INT;
END_VAR

       (* Calculate a new time (e.g. 14 days prior to current) *)
       AnalogTime := SUB_DT_TIME(NOW(),MAKE_TIME(14,0,0,0,0));

       (* Set quality: 0 is Bad, 192 is Good *)
       AnalogQuality := 192;

       (* Change Count's value for the next time this program is run *)
       Count := Count + 1;
       IF (Count > 100) THEN
               Count := 0;
       END_IF;

       (* Set value to a changing integer *)
       Analog := Count;


END_PROGRAM


Ensure your historic lifetime is long enough to allow storage of the data, and also that the date/time isn't inside the archive period as the data from that time is read only and you will not get an error.

If you are having problems with it correctly showing the quality, set the Update Outputs properties on the structured text to be Always.