Program Tag

Introduction

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
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.
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.

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

Dynamic Properties

PropertyTypeDescription
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 zero value shows success. A non-zero value shows 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 EventSeverityOperator of this Program tag to 0 (zero). 
    This avoids writing a large number of similar events to the event log. *)
Program Main
    Var 
        (* 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; 
    End_Var

    (* 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;
        End_If

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

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.

Glossary

For the meaning of terms used in Fernhill SCADA.