Initialization and cycle methods

Since the Plastic Base Application concept frequently works with reference values such as interfaces, it must be ensured that the reference values used have a valid assignment. In order not to additionally burden the runtime by the constant validation of these assignments, the Plastic Base Application implements a concept for the initialization of an object.

The access of invalid reference values mainly concerns the call of cycle methods of a Plastic Base Application object. For this reason, an object must have been successfully initialized before the cycle method may be executed.

Initialization and cycle methods 1:
Initialization and cycle methods 2:

Handling with the FB_BaseRuntime class recommended

All the initialization steps and cycle calls described below can be implemented using FB_BaseRuntime. This means that objects only have to be passed to the runtime. If the initialization steps fail, corresponding information is output via the TcEventLogger.

SetHMI() method

By means of the SetHMI() method an HMI parallel class can be passed to the main class. The method must always be executed before the Init() method, unless the class also works without HMI parallel class.

Error code

Abbreviation

Description

0x701

SrvNotSupported

The class does not support HMI parallel class.

0x71B

InvalidInterface

The passed interface is invalid.

Init() method

The Init() method is used to check the initialization state in addition to setting and configuring reference value assignments. Accordingly, when initializing an object, the HRESULT return value of the method must be checked. If the execution of the Init() method is unsuccessful, an error exists in the structure of the program codes. This error must be solved on code level.

Initialization and cycle methods 3:

Use of the BaseState

Redundantly to the return value of the Init() method, the BaseState of the base class FB_Base can also be checked for a value greater than E_BaseState.eInit.

Cyclic() method

The Cyclic() cycle method acts as an object-oriented version of a class instance call. I.e., the method is usually called once per cycle to process procedures and/or updates. The routines implemented in the Cyclic() method are mostly medium priority mechanisms. Therefore, this method is suitable for the implementation of a predefined command sequence or the processing of control commands from the HMI (e.g. the implementation of manual functions).

ParamInit() method

The ParamInit() method is used to initialize parameters. I.e., in this method, hardcoded default values are defined with which commissioning is started without preconfigured machine data. Since asynchronous communication may also be required in this method, execution may continue over several cycles until the HRESULT return value signals the success of the operation. It is recommended to add a timeout to detect a failure of the execution.

Initialization and cycle methods 4:

Loading the machine data

If loading machine data from a file is desired when starting the machine, this is not possible in the ParamInit() method. Therefore, implement a separate procedure that starts following the successful execution of ParamInit(). This is implemented by the FB_BaseRuntime class in the Plastic Application project.

CoreCyclic() method

The special modification of a Cyclic() method as CoreCyclic() can be found again with individual classes such as FB_Axis. This method handles particularly real-time critical tasks such as calling the cycle method of a TF8560 axis. Since such an axis also contains control algorithms, it is recommended to choose the cycle time as small as possible (standard 2 ms).