User manual

Toolbox 32 User Manual 1.47d www.cse-semaphore.com/mykingfisher
Page
88
Ladder Logic - Function And Program Blocks
Function Blocks allow commonly used pieces of logic to be defined once and then re-used as many times as
necessary. Up to 32 variables can be passed to a function block and then used within the function block.
Variables are referenced by "%number"; eg. the third parameter would be referenced as "%3".
A function block definition commences with a Start Function Block, and ends with a Return from Function
Block. The function block is called or run from ladder logic by using a Call Function Block.
A function block can be configured as an input by defining a Boolean (true or false) return parameter, or as
an output by not defining a return parameter as detailed below. A function block can also be used to call
another function block. This can occur multiple times so that one function block call can trigger a string of
function block calls.
Rules for Configuring Function Blocks
All function blocks must be placed at the end of a ladder logic configuration after the normal (main loop)
ladder logic. The compiler will search for the first Function Block Start and terminate the normal ladder
logic there.
All function blocks must end with an unconditional Return from Function Block, ie. one directly connected
to the left power rail. However, a function block may contain any number of conditional returns.
Function block names are case sensitive: the name in a Call Function Block must exactly match the
name in a Start Function Block.
The number of variables and the data types in a Call Function Block must exactly match those defined in
the corresponding Start Function Block.
A function block defined without any return parameter can only be called from an output position (the
right-most column).
A function block defined with a Boolean return parameter can only be called from an input position (any
column except the right-most one).
Timer and edge trigger ladder blocks cannot be used within function blocks. (Note: a timer can be
created using #YTICK.SEC to increment or decrement a register. An edge trigger requires the current
value to be compared to the previous value (a bit or register), to see if it has changed. The current value
is then copied to the previous value for use in the next scan.)
Up to 500 Call, Jump and Start Function blocks (in total) can be used per RTU.
Function blocks defined in another ladder logic file may be called by the main ladder logic file by using a
Project file. This is useful when there are many RTU sites that all use the same piece of ladder logic. If a
change needs to be made, only the one ladder logic file needs to be updated and then the ladder logic for
each site is re-compiled. Please see the topic Ladder Logic, Multiple Ladder Files.
Function blocks for DNP3 objects are available from www.cse-semaphore.com/mykingfisher.