Basic Function Block
The Sequencer Basic Block can be used to make new Sequencer blocks using the No-Code approach. This provides a quick way for adding custom reusable sequential steps with desired control behavior to your library. It is also possible to build regular cyclic state machines with the Basic Block or conditional execution control branching (if-else branching for regular operators).
To understand Sequencer base consepts, read also the Introduction page.
Execution Control Chart (ECC)
The block's behavior is controlled by states making up the Execution Control Chart (ECC). Transitions between states may require input events and/or transition condition evaluating to true allowing transition to next Sequencer - State. The transition condition is held by transition Value
property.
The Basic Block is by default processed when input event arrives. The Sequencer input events are consumed when they are required by a transition and can only trigger one such transition during the process run.
Transitions without conditions will be taken immediately. The exact transitioning behavior can be controlled by TransitionMode
property. The total number of transitions that can be taken during the process run is also limited by TransitionLimit
property.
When ECC transitions to new Sequencer - State it will process operations linked to that state. If those operations produce output events they are emitted and sent when connected to block output events.
The ECC state can at any time be overridden by setting OverrideState
and OverrideStateMachine
properties.
Note: By default, Basic Block is processed when events arrive, even if those events are not connected internally or are connected to other states transition(s).
Note: This Basic Block requires C mode to be set in ProcessOn
property to periodically evaluate the Wait.Time > 3
in transition condition. All states have Time
property, accessible in transition conditions, that indicates time spent in state after arriving. Enabled
variable in the first condition refers to input data argument Enabled.
Examples
To better explain the Basic Block behavior in different ProcessOn
modes some example blocks are provided.
Simple Block
The following example represents the default Basic Block setup where processing is only triggered by events and all possible transitions are taken each time processing occurs.
The block executes either BigOp
or SmallOp
operation depending on the value of DataIn
, each time EventIn0
arrives and updates DataOut
with the value from the executed block. Regardless of what operation is executed it always emits EventOut0
.
The slowed-down diagram video clip shows Event-based processing. Note that the actual processing happens during the same message handling callback and for any external observer at the same time.
The processing of the block starts when input event EventIn0
arrives. At event arrival values for all data inputs are synchronized. Currently, the event itself does not contain any data to over-assign data inputs.
EventIn0
is connected to two possible transitions exiting the initial Null
state. Both transitions also have a condition expression that gets evaluated. Because the value of DataIn
is currently 7
, DataIn <= 10
evaluates to true
, causing the ToSmall
transition to be taken and EventIn0
to be consumed.
On entering the WorkSmall
state all operations linked to the state get executed. RunOp0
run operation runs the SmallOp
operation.
The SmallOp
is processed, its data synchronized to connected output arguments and then Done
event is emitted. As the Done
event is connected to EventOut0
output event, it also gets emitted.
After processing linked operation in WorkSmall
state, its transition is evaluated and taken as it has no additional conditions set.
The Basic Block arrives back at Null
state, there is no operation to execute and all transitions require {Sequencer - EventIn} {event} EventIn0
that was already consumed.
At this stage, the processing of the Basic Block stops and the next event is needed to trigger processing.
Note: If Null
state transitions would not require EventIn0
to proceed, the state machine would get into an endless loop. This loop would be stopped when the taken transition count reaches TransitionLimit
and a configuration alarm about the loop detected would be set.
Simple Wait Block
The following example represents a Basic Block setup where processing is triggered both by events and parent cycles with all possible transitions taken each time processing occurs.
The block executes Operation
three seconds after EventIn0
arrives when Enabled
is also true at the time and emits EventOut0 when done. If the second EventIn0
arrives during the waiting period, it will be ignored.
The processing of the block starts when input event EventIn0
arrives while the Enabled
is also true
. When this occurs ToWait
transition is taken.
Note: While waiting for the event, this block is also continuously processed during parent cycles, but as the only transition out of Null
state requires an event, cycles in Null
state are ignored.
In Wait
state, the event processing stops as the ToWork
transition is not possible to traverse due to the Wait.Time
(timer property of Wait
state) not being greater than 3 seconds
yet.
At each parent cycle, the expression Wait.Time > 3
is evaluated and after 3 seconds it will become true, allowing the ToWork
transition to be taken.
Finally, on entering the Work
state the operations linked to the state are executed. Mul2
operation multiplies input data with 2
and provides output data. The operation also emits Done
event that in turn emits EventOut0
.
The ECC transitions back to the Null
state and will remain there until the next EventIn0
is received.
Properties
Basic Function Block has properties to set up desired behavior and get information about its operation.
Property | Description |
---|---|
CurrentState | Displays the current state of the ECC. |
InactiveStates | Should list all states that are considered inactive, when empty the InitialState is considered to be the inactive state. Blocks Active property will be set to false in all inactive states and true in all other states. |
InitialState | Sets the initial state of the ECC, when empty the first state is considered to be the initial state. |
ProcessOn | Sets when the block is processed.
|
TransitionMode | Define how transitions are handled in each processing run. Default without any flags set is all possible transitions are evaluated and taken each process run.
|
TransitionLimit | Internal property limiting the maximum number of transitions that can be taken per process run before looping is stopped with infinite loop alarm. |
OverrideState | Internal property to set the state for overriding block ECC's CurrentState with OverrideStateMachine property. |
OverrideStateMachine | Internal property to override the ECC state machine state with the state in OverrideState. |
Active | Internal property indicating if ECC is considered to be in active state (any state not listed in InactiveStates ). |
See also Sequencer - EventIn, Sequencer - State, Sequencer - StateTransition, Sequencer - EventOut, MessageArgument, ReceiveMessage, and SendMessage.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.