Adapting inner procedures of a class (FB)
Some classes contain inner flows/procedures which are to be extended/changed by inheritance levels or adapted by the application. This is realized with the FB_AdaptableSequence class.
- 1. Create a new class (FB) and let it inherit from a class with inner procedure.
FUNCTION_BLOCK FB_AdaptableClass EXTENDS FB_Extruder
VAR
END_VAR
- 2. Overwrite the internal callback method with the integrated procedure.
In the case of theFB_Extruder
class, the internal procedure is implemented in thePowerStates()
method.
METHOD PROTECTED PowerStates
VAR_INPUT
END_VAR
- 3. Add a query to the callback method for its process step, whether you want to extend an existing sequence or add a new one, and if you have an existing implementation, whether you want to execute it or skip it.
- 4. Evaluate whether calling the existing implementation before or after its new implementation makes sense. Calling the SUPER^ method is only necessary if you continue to use the existing sequences.
// React on existing sequence state
IF aSeqBaseMembers[E_ExtruderPowerStates.eStartVeloFeed].IsActive THEN
;
// Call return to replace exisiting implementation
RETURN;
END_IF
// Define additional/replacing sequence state
IF fbSetProdTurnrate.IsActive THEN
;
RETURN;
END_IF
Platzieren Sie den SUPER^ Aufruf der Callback Methode.
- 5. Define the condition at which the sequence is completed.
// React on existing sequence state
IF aSeqBaseMembers[E_ExtruderPowerStates.eStartVeloFeed].IsActive THEN
// Set FB_AdaptableSequence interface locally
iSeq := aSeqBaseMembers[E_ExtruderPowerStates.eStartVeloFeed];
IF bAdditionalAction THEN
nSaveValueToThis := 10;
// command a jump to a state that is not the default "next" element
iSeq.Jump(fbSetProdTurnrate);
// feedback on finishing the sequence state
iSeq.Done := TRUE;
END_IF
// Call return to replace exisiting implementation
RETURN;
END_IF
// Define additional/replacing sequence state
IF fbSetProdTurnrate.IsActive THEN
// Set FB_AdaptableSequence interface locally
iSeq := fbSetProdTurnrate;
IF bAdditionalAction THEN
nSaveValueToThis := 10;
iSeq.Done := TRUE;
END_IF
RETURN;
END_IF
// Call implementation of other sequence steps
SUPER^.PowerStates();
- 6. [Only when adding]: Instantiate an instance of type
FB_AdaptableSequence
in the class with the name of the sequence.
FUNCTION_BLOCK FB_AdaptableClass EXTENDS FB_Extruder
VAR
fbSetProdTurnrate: FB_AdaptableSequence;
END_VAR
- 7. Insert the sequence in the initialization at the desired position.
IF NOT F_SucceededHr(SUPER^.Init(), Init) THEN
RETURN;
END_IF
fbPowerStates.Insert(
iCurrent := aSeqBaseMembers[E_ExtruderPowerStates.eMasterMode],
iNew := fbSetProdTurnrate,
bOverwrite := FALSE);
- 8. Apply the changes to your target system and restart the PLC.
- You have successfully extended an inner procedure of a class.