Skip to content

Initialize and CyclicLogic

The Initialize() and CyclicLogic() methods are used by both the FB_PackML_BaseModule and the FB_ComponentBase. These are extended to create Machine Modules, Equipment Modules, and Components. Without these two methods the framework doesn’t function.

Initialize

The Initialize() method of FB_ComponentBase simply calls the CreateEvents() Method and returns TRUE. This ensures that the EventClasses of the component are properly configured and provides consistency in program design by allowing us to override the Initialize() method when we inherit from FB_ComponentBase. The Initialize() method of the FB_PackML_BaseModule is more complex. In addition to calling the CreateEvents() method it also creates a list of SubModules and Components that the Module is responsible for controlling. It then calls the CyclicLogic() method of each of these. This call is done in order to allow each of these to call their respective Initialize() methods. Because an Initialize() method will take multiple scans to complete, the method is continually called until it returns TRUE at the end of the CASE statement. This program design also requires us to first call the Initialize() method at the beginning of any CyclicLogic() method if it has not been completed. The variables and methods required for this are already declared in the base classes.

Each Initialize() method will return TRUE, therefore ultimately setting _InitComplete to TRUE which is declared within FB_CyclicFB, which is a parent of FB_PackML_BaseModule. The InitComplete variable is a property that will get the _InitComplete variable. Once the Initialize() method has finished for all SubModules and Components the CyclicLogic() methods will run for all of them as long as each Child calls SUPER^.CyclicLogic().

CyclicLogic()
1
2
3
4
5
6
    IF NOT _InitComplete THEN
        _InitComplete := Initialize();
        RETURN;
    END_IF

    SUPER^.CyclicLogic();

CyclicLogic

It is important for all CyclicLogic() methods to be called Cyclically. While this might seem obvious, there will be times when you might want to alter this, and it is important not to do so. If you have code that is not needed Cyclically then call it conditionally from the Cycliclogic() method, but always call the CycliLogic() methods. This will ensure that the internal hierarchy of CyclicLogic() methods and the state machine is never broken.

As programs grow it will become necessary to break up the code within the CyclicLogic() method into smaller helper methods or simply into digestible chunks of code.

The First call to CyclicLogic() of the Machine Module can be handled at a couple of different levels. Some prefer to add a CyclicLogic() method onto the MAIN POU, which is acceptable, but then you must also add the Initialize() method to MAIN. The other option is to declare Machine : FB_Machine; within MAIN (assuming that FB_Machine EXTENDS FB_PackMLBaseModule) and then letting MAIN call Machine.CyclicLogic();. While this is the simplest way to get started there can be some benefits to MAIN having its own Initialize() method that runs once before the remaining code is Initialized and run.