CAA Technical Workgroup
CAA Callback Extern
3.5.17.0
Intern|CAA|Runtime
CB
3S - Smart Software Solutions GmbH
CAA Callback
In the runtime system different events occur. Each event can be assigned to an event class. Further on each event arises from a certain source. The runtime system has an internal list of registered callback definitions. At each occurring event the runtime system checks its list of callback definitions and if applicable calls a callback function.
A callback definition consists of:
Event
Event class
Event source
Index of the function which should be called as soon as the event occurs.
Event e of class c from source s triggers the callback (e, c, s), if
(e = e OR e = CB.ALL_EVENTS) AND
((c AND c) > 0 OR c = CB.ALL_CLASSES) AND
(s = s OR s = CB.ALL_SOURCES)
A function which should be used as callback function, must have the following interface:
FUNCTION Callback<Name> : BOOL
VAR_INPUT
dwSpec : DWORD; (* CB.Event and CB.EventClass *)
dwParam : DWORD; (* Application specific Parameter *)
dwSource : DWORD; (* CB.EventSource *)
END_VAR
The data types are DWORDs in order to be compatible to CODESYS V2.3. These however refer to the enumerations specified in brackets. Parameter dwSpec via function CB.DecodeEvent and CB.DecodeClass can be split in two variables of type CB.Event and CB.EventClass. The parameter dwSource can be converted to data type CB.EventSource with the help of the DWORD_TO_INT conversion.
CODESYS V3.x:
As from CODESYS 3.x the POUs are not addressed any longer by an index. Due to this fact the structure and the interpretation of the CB_Callback data type must be adapted correspondingly. The interface of function CallFunctionByIndex also changes.
On the structure and usage of the callback functions:
The function name must have a prefix „Callback”.
The function must not contain any local variables.
The function must not be checked with breakpoints.
CODESYS V3.x:
The function muss be parameterized with property Enable system call!
Multiple callbacks may be assigned to one event. A callback (event, -class, -source, function index) however can get registered only once; if one tries to assign an identical callback, CB_RegisterCallback will dump an error.
After a reset of the PLC all registered callbacks will be deregistered immediately. Callbacks, which are possible registered on event CB_AFTER_RESET, will be called once more before the automatic deregistration.
Regard that callback functions can be called immediately after the event has occurred. Thereby an currently running IEC task can be interrupted. The programmer must be aware that this might raise similar problems like there are in multitasking systems (data consistency etc.); besides that the run time of a callback function should be kept as short as possible, because it blocks the whole system.
The return value of the callback function is of no significance .