Program Tag


The Program Tag extends the Core Tag to execute an IEC-61131-3 Program at a defined interval.

Configuration Properties

The Program Tag supports the configuration properties of the Core Tag plus these additional configuration properties:

Property Type Version Description
Interval TIME 2.0 The interval between each execution. See Interval and Offset for information on how Intervals and Offsets define the time of activities.
Offset TIME 2.0 The offset added to the Interval to get the actual update time See Interval and Offset for information on how Intervals and Offsets define the time of activities.
InstructionLimitUDINT 2.0 The maximum number of instructions before the program is terminated. The intention of the InstructionLimit property is to prevent accidental infinite loops.

The Program Tag executes the IEC-61131-3 Program called Main at the periodic interval defined by the Interval and Offset properties.

Dynamic Properties

Quality INT The quality of the tag
Timestamp DATE_AND_TIME The timestamp of the last program execution.
ExecErrorCode DINT The result of the execution. A value of zero indicates success. A non-zero value indicates an error occurred.
ExecErrorLocation DWORD The address of the instruction that caused the error. Zero if there was no error.
ExecInstructionCount UDINT The number of instructions processed by the program during the latest execution.
ExecutionTimer TimerStatus The status of the program execution timer.

Tag Commands

The Program Tag supports these tag commands:

Tag Command Version Description
Run 2.0 Runs the program.

Relationships to Other Tag Types

The Program Tag builds on the features of these tag types:

Edit Program Code

To Edit the program code:

  1. Right click on the Program tag in Tag Window.
  2. Select Edit source code.

In the code editor you can use any of the features in the IEC-61131-3 Common Elements to create code.

To access Fernhill SCADA from the program you can also use these additional function blocks:

Example Program

This example uses the TagWriteValue function block to reflect the value of one tag to another:

(* Note: Set the TrackingEventSeverity of this Program tag to 0 (zero) 
    to avoid spamming the event log *)
Program Main
        (* Function block to write a value to a tag*)
        T : TagWriteValue;

        (* Flag set to true to start the update *)
        StartUpdate : BOOL;
        (* Timestamps of the source tag used for change detection *)
        PreviousTimestamp, NewTimestamp : DATE_AND_TIME; 

    (* If the TagWriteValue function block is not busy and the
        source tag timestamp is different to the last timestamp we processed,
        StartUpdate will be set to TRUE for 1 cycle.  This will start a new update
        of the TagWriteValue function block *)
    StartUpdate := False;
    (* If the TagWriteValue function block is not busy... *)
    if Not( T.BUSY ) Then
        (* Get the timestamp of the source tag *)
        NewTimestamp := %".Source.Timestamp";

        (* Has the timestamp of the source tag changed ? *)
        if NewTimestamp <> PreviousTimestamp Then
            (* We want to start the update *)
            StartUpdate := True;

    elseif T.DONE AND NOT T.ERROR Then
        (* The TagWriteValue function block has completed without error, 
            update the previous timestamp *)
        PreviousTimestamp := NewTimestamp;
    (* Remember to substitute an appropriate tag name *)
    T( Req:=StartUpdate, TagName:="-- Full Name of target --", Value:=%".Source.Value" );

Further Information

Interval and Offset

To learn how activities are scheduled using Interval and Offset.

IEC-61131-3 Program

To learn about Programs you can edit.

Core Data Driver

To learn about the Core Driver.


For definitions of the terms used in Fernhill SCADA.