Function Block

What is Function Block

A function block is a POU (program organization unit), which returns one or several values when executed.

It is similar to a class in any programming language which can be instantiated and executed with a different value.

Function block in the structured text has a similar meaning. Let’s say we have 20 similar pumps in our plant. If we want to model these pumps then we can create 1 function block and then make 20 instances of that function block. So we don’t need to model 20 times. It is similar to class in C++ where we can make an instance and give the input  and get the output.



Function Block example

//Soon we edit this…..



org : DINT :=12;

dest : DINT :=13;

another : DINT := 14;

myTimer : TON;

startTimer : BOOL := FALSE;




myTimer(IN:= startTimer, PT:=T#1S);


MEMCPY(ADR(dest), ADR(org),4);

MEMCPY(ADR(another), ADR(dest),4);


IF myTimer.Q = TRUE THEN

myTimer(IN:= FALSE);

org:= org +1;