How to Use a Function or a Function Block in ST Language

General Information

This part explains how to implement a Function and a Function Block in ST language.

Function SetRTCDrift and Function Block TON are used as examples to show implementations.

Using a Function in ST Language

This procedure describes how to insert a function in ST language:

Step

Action

1

Open or create a new POU in Structured Text language.

NOTE: The procedure to create a POU is not detailed here. For more information, refer to Adding and Calling POUs.

2

Create the variables that the function requires.

3

Use the general syntax in the POU ST Editor for the ST language of a function. The general syntax is:

FunctionResult:= FunctionName(VarInput1, VarInput2,.. VarInputx);

To illustrate the procedure, consider the function SetRTCDrift graphically presented below:

Function

Graphical Representation

SetRTCDrift

G-SE-0004463.1.gif-high.gif

 

 

The ST language of this function is the following:

Function

Representation in SoMachine POU ST Editor

SetRTCDrift

PROGRAM MyProgram_ST
VAR myDrift: SINT(-29..29) := 5;
myDay: DAY_OF_WEEK := SUNDAY;
myHour: HOUR := 12;
myMinute: MINUTE;
myRTCAdjust: RTCDRIFT_ERROR;
END_VAR

myRTCAdjust:= SetRTCDrift(myDrift, myDay, myHour, myMinute);

Using a Function Block in ST Language

This procedure describes how to insert a function block in ST language:

Step

Action

1

Open or create a new POU in Structured Text language.

NOTE: The procedure to create a POU is not detailed here. For more information on adding, declaring and calling POUs, refer to the related documentation.

2

Create the input and output variables and the instance required for the function block:

oInput variables are the input parameters required by the function block

oOutput variables receive the value returned by the function block

3

Use the general syntax in the POU ST Editor for the ST language of a Function Block. The general syntax is:

FunctionBlock_InstanceName(Input1:=VarInput1, Input2:=VarInput2,... Ouput1=>VarOutput1, Ouput2=>VarOutput2,...);

To illustrate the procedure, consider this example with the TON function block graphically presented below:

Function Block

Graphical Representation

TON

G-SE-0004465.1.gif-high.gif

 

 

This table shows examples of a function block call in ST language:

Function Block

Representation in SoMachine POU ST Editor

TON

G-SE-0004468.1.gif-high.gif