The wrapper FB is the entry point into the OOP hierarchy of the AX library. The number of wrapper FBs in a library is not limited. Wrapper FBs should each reflect an independent high-level workflow. They should not be used to access single methods of a class. Wrapper FBs are authored by the AX library writer and are not auto generated by AX2TIA.
The following example shows a wrapper FB:
NAMESPACE ExampleClassLib
CLASS Belt
METHOD PUBLIC RunForward ; END_METHOD
METHOD PUBLIC RunBackward ; END_METHOD
METHOD PUBLIC Stop ; END_METHOD
END_CLASS
CLASS ABSTRACT Conveyor
METHOD PUBLIC ABSTRACT Run END_METHOD
METHOD PUBLIC ABSTRACT Stop END_METHOD
END_CLASS
CLASS OneBeltConveyor EXTENDS Conveyor
VAR PUBLIC
belt : REF_TO Belt;
END_VAR
METHOD PUBLIC OVERRIDE Run
belt^.RunForward();
END_METHOD
METHOD PUBLIC OVERRIDE Stop
belt^.Stop();
END_METHOD
END_CLASS
CLASS TwoBeltConveyor EXTENDS Conveyor
VAR PUBLIC
belt1 : REF_TO Belt;
belt2 : REF_TO Belt;
END_VAR
METHOD PUBLIC OVERRIDE Run
belt1^.RunForward();
belt2^.RunBackward();
END_METHOD
METHOD PUBLIC OVERRIDE Stop
belt1^.Stop();
belt2^.Stop();
END_METHOD
END_CLASS
END_NAMESPACE
The following wrapper FB uses the class toolbox and provides a workflow that drives an equipment module with two belts. The workflow for EquipmentModule1 is controlled from the outside by start and stop. The implementation of EquipmentModule1 knows that it consists of two belts and knows how they are to be controlled (for example that they need a delay of 10s to switch on and off).
NAMESPACE ExampleClassLib.Entry
FUNCTION_BLOCK EquipmentModule1 // Wrapper FB
VAR_INPUT
start : BOOL;
stop : BOOL;
END_VAR
VAR // OK, classes can be instantiated in VAR
belt1, belt2, belt3 : Belt;
feed : OneBeltConveyor;
transport : TwoBeltConveyor;
init : BOOL := TRUE;
END_VAR
IF init THEN
init := FALSE;
feed.belt := REF(belt1);
transport.belt1 := REF(belt2);
transport.belt2 := REF(belt3);
END_IF;
IF start AND NOT stop THEN
feed.Run();
// wait 10s
transport.Run();
ELSIF stop THEN
transport.Stop();
// wait 10s
feed.Stop();
END_IF;
END_FUNCTION_BLOCK
END_NAMESPACE