Table of Contents

UnitStateMachineImpl

Namespace
ZApplication
Extends
Inherited Properties
Inherited Methods
Implements
FUNCTION_BLOCK UnitStateMachineImpl EXTENDS ZAux.StateMachineImpl IMPLEMENTS ZCore.IHaltable, ZCore.IManagedObject, ZCore.IBootable, ZCore.IObject, ZCore.IError (
 [output] State : ObjectState)

This function block is a specialised implementation of a StateMachine for Units. It defines the Zeugwerk Template UnitStateMachine and has a proper initialization for it. For more information on this topic UnitStateMachine please read the docs under here

Constructor

FB_init

METHOD FB_init (
 [input] bInitRetains : BOOL,
 [input] bInCopyCode : BOOL,
 [input] parent : ZCore.IManagedObject) : BOOL

The constructor of ManagedObject takes a parent as parameter, which is then notified about the creation of this instance.

Inputs

bInitRetains BOOL

if TRUE, the retain variables are initialized (warm start / cold start)

bInCopyCode BOOL

if TRUE, the instance afterwards gets moved into the copy code (online change)

parent IManagedObject

Interface to a valid parent, which usually forwards this instance to an ObjectManager

Returns

BOOL

Properties

Error

PROPERTY Error : BOOL

This property can be used to check if the UnitStateMachine is on Error or not It returns TRUE if the current state index is UnitStateMachineState.Fault or if the error happend at Booting time on UnitStateMachineState.BootFault or if it is UnitStateMachineState.Undefined. Otherwise this property will return FALSE.

Property Value

BOOL

Halting

PROPERTY Halting : BOOL

The object is currently prematurely ending its cyclic method. Use this property to test, if the object corresponded correctly to a halt command (usually issued by a CancellationToken). Use the result to appropriately react. Sequences that should be halted, but do not support a dedicated halting mechanism, should either be waited for with a timeout or stopped.

Userdefined action can not be halted

Property Value

BOOL

ListenerProcessor

PROPERTY PROTECTED ListenerProcessor : REFERENCE TO ZAux.StateMachineListenerProcessor

Property Value

REFERENCE TO StateMachineListenerProcessor

Methods

FinalState

METHOD FinalState (
 [input] step : ZAux.StateMachineStep,
 [input] statemachineState : INT) : INT

Defines the state that should be automatically transitioned to, once the sequence that is optionally mapped to a state is not busy anymore. The ZCore.ObjectMock that is passed as a parameter is used to determine if the sequence failed with an error or finished successfully, respectively. The parameter statemachineState contains the state that the statemachine is currently in.

This method is a specialisation for the UnitStateMachine and has its proper logic implemented For more information on the Unit Statemachine please refer to the docs here

Inputs

step StateMachineStep

Is used to determine if the prevous sequence has failed with an error or finished successfully

statemachineState INT

This parameter contains the state that the statemachine is currently in

Returns

INT

IsTransitionAllowed

METHOD IsTransitionAllowed (
 [input] fromState : INT,
 [input] toState : INT) : BOOL

The state machine controls all transitions and checks if a specific transition is allowed. This method does all those checks for the predefined UnitStateMachine. When changing from one state to another, this method checks if this is allowed and returns TRUE. For example a direct change from state init to state automatic is not possible, in this case this method returns FALSE.

Inputs

fromState INT

usually an enumeration containing all states of this statemachine

toState INT

usually an enumeration containing all states of this statemachine

Returns

BOOL

SetState

METHOD SetState (
 [input] state : INT) : BOOL

This method can be used to force the statemachine into a specific state. In contrast to TransitionAsync the change is abruptly and will not stop an optionally already running sequence.

This method should only be used to set the initial state of the statemachine and not for controlling a sequential flow. For the later purpose, TransitionAsync should be used, which performs a "clean" transition from one state to another.

Note

UnitStateMachineState.Halt is a special state, which can not be set explicitly, but only throw the CancellationToken. passed in TransitionAsync. Any attempt to force the state to halt results in a not-recoverable booting error.

Inputs

state INT

usually an enumeration containing all states of this statemachine

Returns

BOOL

SetStateSequence

METHOD SetStateSequence (
 [input] stateIndex : INT,
 [input] sequence : ZCore.ISequence,
 [input] flags : WORD)

If a state is associtated with a sequence the Cyclic method of the statemachine takes care of executing this sequence until the sequence is not busy. Then the FinalState method is used to automatically transition into the state that is configured there.

Note

stateIndex has to be greater than 0 and equal or smaller than MaxStates.

While the statemachine is in a state that has an associated sequence, the statemachine is regared as Busy.

The parameter flags is free to use by every actual StateMachine implementation.

Note
  • Userdefined states and actions have to have stateIndex >= UnitStateMachineState.Last
  • Predefined states (as defined in UnitStateMachineState) have to have stateIndex < UnitStateMachineState.Last
  • UnitStateMachineState.Halt and UnitStateMachineState.Halt are special states, which can not be mapped to a sequence. If any of these rules is not regarded, the statemachine transitions into a not-recoverable booting error due to misconfiguration.

Inputs

stateIndex INT

Any entry in UnitStateMachineState with the exception of UnitStateMachineState.Halting

sequence ISequence
flags WORD

StateDecoded

METHOD StateDecoded (
 [input] state : INT) : ZCore.ZString

Returns the given state decoded as String for proper logging

Inputs

state INT

usually an enumeration containing the state which should be decoded

Returns

ZString

StateIndex

METHOD StateIndex () : INT

Returns

INT

TransitionAsync

METHOD TransitionAsync (
 [input] startToken : ZCore.IStartToken,
 [input] state : INT) : BOOL

This method is used to perform a "clean" transition from the current state of the statemachine to state, but only if the transition is allowed.

The state change is not performed instantly, but only in the next call of the Cyclic method, which is usually automatically called by an object manager or the parent of this object.

Inputs

startToken IStartToken
state INT

usually an enumeration containing all states of this statemachine

Returns

BOOL