IBehaviourModel (ITF)

INTERFACE IBehaviourModel EXTENDS __SYSTEM.IQueryInterface

Implemented by the function block BehaviourModel.

This interface provides all methods and properties which are necessary for controlling a BehaviourModel instance via interface reference variables.

When operating via an interface reference variable it should be possible to decide exactly when the state machine is called. For this the methods StartModel, AbortModel, ResetModel and GetModelState has a parameter xCommit. Calling one of these methods with the value xCommit:=FALSE will only prepare the state changes and will not trigger the state machine to execute the related actions for changing the state. Calling one of these methods with the value xCommit:=TRUE will prepare the state changes and will then trigger the state machine to execute the necessary action to reach the next stable state. It is important to know, that the state machine sometimes needs more than one invocation to transit from on state to the next stable state. With this in mind the following code example might be useful for handling a common behaviour model via an interface reference variable.

A code example for handling a common behaviour model via an interface reference variable

VAR
    itfBehaviourModel : CBML.IBehaviourModel;
    eState : CBML.STATE;
    /// Some variable to trigger the abort of the behaviour model
    xSignal : BOOL;
END_VAR

CASE eState OF
    CBML.STATE.DORMANT:
        (* Prepare execting *)
        itfBehaviourModel.StartModel(xCommit:=FALSE);

    CBML.STATE.DONE:
        (* Handle the ``Done`` state *)
        itfBehaviourModel.ResetModel(xCommit:=FALSE);

    CBML.STATE.ABORTED:
        (* Handle the ``Aborted`` state *)
        itfBehaviourModel.ResetModel(xCommit:=FALSE);

    CBML.STATE.ERROR:
        (* Handle the ``Error`` state *)
        itfBehaviourModel.ResetModel(xCommit:=FALSE);
END_CASE

IF xSignal AND
   eState = CBML.STATE.STARTING OR
   eState = CBML.STATE.EXECUTING
THEN
    itfBehaviourModel.AbortModel(xCommit:=FALSE);
END_IF

itfBehaviourModel.GetModelState(xCommit:=TRUE, eState=>eState);

There is a very important aspect of this code example: The state machine should definitely be called/triggered only once in a PLC cycle!