Programming own FBs: Always declare motion axes (AxisRef) from the device tree as 'VAR_IN_OUT'

Question:
Programming your own function blocks (FB) in the PLC Designer project:
  • What must be considered for accessing the data of a motion axis (AxisRef)?
  • How are motion axes correctly declared?
Answer:
In programming terms, motion axes (Axis_Ref) from the device tree or axis groups are not simply variables, but function blocks with their own program code. They are automatically called up cyclically by the PLC.
The declaration must therefore be made differently.

'VAR_INPUT', 'VAR_OUTPUT':
  • Variables and variable structures are declared as 'VAR_INPUT' or 'VAR_OUTPUT' for value transfer to an FB.
  • This creates additional variables in the FB and allocates its own memory space.
  • To transfer the data to the FB inputs, a correspondingly large number of copying processes take place.
'VAR_IN_OUT':
  • Motion axes (AxisRef), on the other hand, must be declared as 'VAR_IN_OUT'. 
  • This module interface works according to the "call by reference" principle.
  • The memory ranges of the motion axis are accessed directly via this interface.
Example of correct programming for integrating a motion axis via the VAR_IN_OUT element:
FUNCTION_BLOCK  Test
VAR_IN_OUT
    Axis:   Axis_Ref;
END_VAR
If a motion axis is incorrectly declared as VAR_INPUT / VAR_OUTPUT:
- the intended functionality is not guaranteed and
- runtime increases due to the cyclical copying of the mostly extensive data of a motion axis.

Automatic Translation

URL for linking this AKB article: https://www.lenze.com/en-de/go/akb/202100385/1/
Kontaktformular