How to Use a Function or a Function Block in ST Language
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 |
![]()
|
The ST language of this function is the following:
Function |
Representation in SoMachine POU ST Editor |
---|---|
SetRTCDrift |
PROGRAM MyProgram_ST 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 |
![]()
|
This table shows examples of a function block call in ST language:
Function Block |
Representation in SoMachine POU ST Editor |
---|---|
TON |
![]()
|