A sub-program is called by another program. Unlike function blocks, local variables of a sub-program are not instantiated, and thus you do not need to declare instances. A call to a sub-program processes the block algorithm using the specified input parameters. Output parameters can then be accessed.
To call a sub-program in ST, you have to specify its name, followed by the input parameters written between parenthesis and separated by comas. To have access to an output parameter, use the name of the sub-program followed by a dot '.' and the name of the wished parameter:
MySubProg (i1, i2); (* calls the sub-program
Res1 := MySubProg.Q1;
Res2 := MySubProg.Q2;
Alternatively, if a sub-program has one and only one output parameter, it can be called as a function in ST language:
Res := MySubProg (i1, i2);
To call a sub-program in FBD or LD languages, you just need to insert the block in the diagram and to connect its inputs and outputs.
To call a sub-program in IL language, you must use the CAL instruction with the name of the sub-program, followed by the input parameters written between parenthesis and separated by comas. Alternatively the CALC, CALCN or CALNC conditional instructions can be used:
CAL Calls the sub-program
CALC Calls the sub-program if the current result is TRUE
CALNC Calls the sub-program if the current result is FALSE
CALCN same as CALNC
Here is an example:
Op1: CAL MySubProg