Common Behaviour ModelΒΆ
Overview of function blocks, Interfaces and decorators which are provided by the CODESYS Common Behaviour Model Library
The library provides a base function block for each behaviour model specified by the PLCopen.
Reusing by Composition
The base function block for all timing controlled function blocks (TimingControlledBehaviourModelBase)
can be created by using composition.
For this the BehaviourModel
function block and a TimingController
function block is incorporated.
The input variables itfActionProvider
and itfTimigController
are initialized properly.
Additionally a set of interfaces is implemented. Every call of a method and every access to a property has to be
delegated to the local BehaviourModel
instance.
The methods of the IActionProvider
interface yield the possibility to adapt them inside the function block by extending the base function block.
The implementation of the methods which are part of the IBehaviourModel
interface (e.g. StartModel
), allow to couple the input and
output variables between the locale BehaviourModel
instance and the input and output variables of the extending function block.
The method GetModelState
was chosen for this task.
The implementation of the body of the base function block is factored out to the protected method _Execute
.
So the behaviour of a call out of the PLC cycle can be modified by the function blocks extending this base function block later.
Using Composition for Creating new Function Blocks
By creating two function blocks, one internal core function block and one public final function block it is possible to encapsulate the complete implementation details.
Using this technique the layout of the public function block is completely decoupled from the layout of the internal function block (See the different naming conventions for variable names).
Because of the FINAL
keyword it is not possible to extend this function block in another context. So no problems can occur after changing
some implementation details (For example adding some local variables).
Because of the INTERNAL
keyword nobody can use a function block marked in this way outside of its defined context, its original library.
Reusing by Inheritance
The base function block for a ETrigTl
behaviour is created by extending the base function block TimingControlledBehaviourModelBase
described in the last chapter.
The common input and output variables are declared. Nearly the complete implementation can be inherited form the TimingControlledBehaviourModelBase
function block.
Only a small amount of code is necessary to adapt the new function block regarding the ETrigTl
specification.
The new function block is now a full member of the BehaviourModel
family.
It may be used as well via its inputs and outputs such as via the implemented interface IBehaviourModel
.
The other function blocks like LCon, LConTl, LConTo, LConTlTo, LConC, LConTlC or ETrig, ETrigTo, ETrigTlTo, ETrigA, ETrigATl, ETrigATo, ETrigATo and ETrigATlTo are generated in the same way.
Using Inheritance for Creating new Function Blocks
To reuse such a base function block outside of the Common Behaviour Model Library it is necessary to
create a new function block that extends the desired base function block from the library.
Additional variables can be added and the specific implementation of its behavior can be
placed into the methods StartAction
, CyclicAction
, CleanupAction
and ResetAction
.
The inherited BehaviourModel
instance will guarantee to call the right method at the right point in time.
- Behaviour Model
- ActionController (FunctionBlock)
- BehaviourModel (FunctionBlock)
- Decorators
- Enums
- ImplementationBase
- Interfaces
- IActionController (Interface)
- IActionController2 (Interface)
- IActionProvider
- IBehaviourModel (Folder)
- IConfigurationProvider (Interface)
- IConfigurationProvider2 (Interface)
- ITimingController (Interface)
- TimingController (FunctionBlock)
- Edge Triggered Function Blocks
- Level Controlled Function Blocks