A function block (
) groups an algorithm and a set of private data. It has inputs and
outputs. A function block can be:
To call a function block in ST, you have to specify the name of the instance, followed by the input parameters written between parentheses and separated by comas. To have access to an output parameter, use the name of the instance followed by a dot '.' and the name of the wished parameter. The following example demonstrates a call to an instance of TON function block:
(* MyTimer is declared as an instance of TON *)
MyTimer (bTrig, t#2s); (* calls the function block *)
TimerOutput := MyTimer.Q;
ElapsedTime := MyTimer.ET;
To call a function block in FBD or FFLD languages, you just need to insert the block in the diagram and to connect its inputs and outputs. The name of the instance must be specified upon the rectangle of the block.
To call a function block in IL language, you must use the CAL instruction, and use a declared instance of the function block. The instance name is the operand of the CAL instruction, followed by the input parameters written between parentheses and separated by comas. Alternatively the CALC, CALCN or CALNC conditional instructions can be used:
CAL |
calls the function block |
CALC
|
calls the function block if the current result is TRUE |
CALNC
|
calls the function block if the current result is FALSE |
CALCN
|
same as CALNC |
The following example demonstrates a call to an instance of TON function block:
(* MyTimer is declared as an instance of TON *)
Op1: CAL MyTimer (bTrig, t#2s)
FFLD MyTimer.Q
ST TimerOutput
FFLD MyTimer.ET
ST ElapsedTimer
Op2: FFLD bCond
CALC MyTimer (bTrig, t#2s) (* called only if bCond is TRUE *)
Op3: FFLD bCond
CALNC MyTimer (bTrig, t#2s) (* called only if bCond is FALSE *)
See also:
Differences Between Functions and Function Blocks
|
Copyright © 2015 Kollmorgen™ |
|