Program Tag

Help Contents


The Program Tag executes an IEC 61131-3 Program. The IEC 61131-3 Program can be configured to run:

Configuration Properties

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

Property Type Version Description
InstructionLimit UDINT 2.0 The maximum number of instructions before the program is terminated. The intention of the InstructionLimit property is to prevent accidental infinite loops.
EnableTrackingEvents BOOL 3.77 Whether tracking events are generated from this program:
  • False - No tracking events are generated from this program.
  • True - The program can generate tracking events.
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.

EnableTrackingEvents Property

When EnableTrackingEvents is True, the program can generate tracking events which are stored in the Event Log. Sources of tracking events include:

When EnableTrackingEvents is False, the program does not generate tracking events for any of the above sources.

A program with EnableTrackingEvents set to True can generate a large number of events. For example, this statement in a Program Tag with an Interval of 1 second would generate 1 tracking event per second:

%"Target Setpoint" := NewSetpointValue;

Most of the events would be duplicates, which makes the Event Log less useful.

If you want to track the actions of a Program Tag, and avoid duplicate events in the event log, use change detection:

FirstRun : BOOL := TRUE;
NewSetpoint, PreviousSetpoint : LREAL;

IF FirstRun THEN

    FirstRun := FALSE;
    %"Target Setpoint" := NewSetpoint;
    PreviousSetpoint := NewSetpoint;

ELSE IF NewSetpoint != PreviousSetpoint THEN

    %"Target Setpoint" := NewSetpoint;
    PreviousSetpoint := NewSetpoint;


Dynamic Properties

Quality INT The quality of the tag
Timestamp DATE_AND_TIME The timestamp of the last program execution.
ErrorMessage STRING The first compilation error. An empty string indicates no compilation errors.
ExecErrorCode DINT The result of the execution. A zero value shows success. A non-zero value shows an error occurred.
ExecErrorLocation STRING The location of any execution error. An empty string indicates 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 EventSeverityOperator of this Program tag to 0 (zero). 
    This avoids writing a large number of similar events to 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; 

    (* Clear StartUpdate. StartUpdate is set to TRUE for one cycle if:
        * the TagWriteValue function block is not busy, and
        * The source tag timestamp is different to the last timestamp.
        When StartUpdate is set to TRUE, a the TagWriteValue function block will be triggered. *)
    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 the meaning of terms used in Fernhill SCADA.