|Download Help (Windows Only)|
Transitions and static reactions rely upon triggers, guards, and actions. These three elements form a logic structure that the statechart uses to determine whether to take a transition or execute a static reaction. The following sections provide more information about these elements.
A trigger is something to which a statechart reacts. For example, a trigger can be a button press or a value change that happens in a caller VI. When you configure a transition or static reaction, you specify which trigger(s) cause the statechart to begin evaluating that transition or static reaction. Statecharts can react only to triggers that are defined for the current active state or superstate.
For example, consider a DVD player. When you press the Play button on a DVD player, the movie begins playing. When you press the Pause button, the movie pauses. The DVD player does not know when you are going to press a particular button, that is, the DVD player only can react to the button you press.
This behavior describes an asynchronous statechart that executes an action only after receiving a trigger. You typically use triggers with asynchronous statecharts, although you can use triggers with synchronous statecharts also.
|Note You may specify a trigger for every transition and static reaction except in the following situations: entry actions, exit actions, and transitions that leave an Initial pseudostate, because these situations react to any triggers received.|
Statecharts can receive triggers from a VI or from the statechart itself. In either situation, you must define the triggers to which a statechart can react. Asynchronous statecharts store incoming triggers in a trigger queue.
|Note Statecharts evaluate transitions before static reactions. Therefore, if you configure a static reaction and a transition to react to the same trigger, the statechart evaluates the transition first.|
You can combine triggers into groups. When you configure a transition or static reaction to react to a group, any trigger in that group can initiate the associated transition or static reaction.
After receiving a valid trigger, the statechart then evaluates the guard associated with that reaction or transition. A valid trigger is one that you have created and specified for the transition or static reaction.
The NULL trigger is the default trigger to which a transition or static reaction reacts in synchronous statecharts. During each iteration of a synchronous statechart, the statechart evaluates NULL transitions and static reactions for the current state. By default, synchronous Run Statechart functions send the NULL trigger to the statechart at every iteration of the statechart.
|Note You can override this behavior by wiring a trigger value to the Trigger input of the Run Statechart function. You then also must configure the transition or static reaction to react to this trigger.|
The Send External Trigger and Send Internal Trigger functions, however, require you to provide a trigger. You can configure the Send External Trigger and Send Internal Trigger functions to send the NULL trigger or another trigger of your choosing to the statechart. The Send External Trigger function only provides triggers to asynchronous statecharts.
You must configure transitions and static reactions to respond to any triggers other than the NULL trigger.
If a transition responds to the NULL trigger and the statechart sends the NULL trigger during every iteration of the statechart, the guard is the primary factor in determining whether the statechart takes a transition.
A guard is LabVIEW block diagram code that the statechart evaluates to determine if the transition or static reaction is valid. After receiving a trigger for a transition or static reaction, the statechart evaluates the guard code. This code, which must return either TRUE or FALSE, determines whether the statechart takes the transition or executes the static reaction. By combining a guard with triggers, you can be more specific about the conditions under which a statechart takes transitions and executes static reactions.
After receiving a specified trigger, the statechart evaluates the guard code. If the guard code returns TRUE, the statechart proceeds with the transition or static reaction. If the guard code returns FALSE, the statechart does not proceed with the transition or static reaction. In this situation, the statechart remains in the state that initiated the transition or static reaction. The statechart then can evaluate other transitions and/or static reactions for that state.
|Note Statecharts evaluate transitions according to the priority you specify.|
For example, a guard can return TRUE if five or more minutes have elapsed since the statechart began executing. This TRUE value means the statechart takes the transition and enters the next state. Otherwise, the guard returns FALSE. This FALSE value prevents the statechart from taking the transition, and the statechart remains in the same state.
|Note Defining a guard is optional. Not defining a guard is equivalent to specifying that the guard returns TRUE always.|
If you add code to a previously empty guard or if you delete all code from a guard, you must re-generate code for the statechart. Click the Generate Code button to generate code that corresponds to the statechart. If you modify an existing, non-empty guard, you do not need to re-generate code for the statechart.
An action is LabVIEW block diagram code that modifies output or state data and/or sends a trigger to the internal queue. The statechart executes actions at different times depending on whether that action is associated with a transition or a static reaction. The statechart executes actions in the following situations:
If the guard code returns FALSE in either situation, the statechart does not execute the action. Defining an action is optional.
|Note In addition to defining actions for transitions and static reactions, you can define entry and exit actions of a state.|
If you add code to a previously empty action or if you delete all code from an action, you must re-generate code for the statechart. Click the Generate Code button to generate code that corresponds to the statechart. If you modify an existing, non-empty action, you do not need to re-generate code for the statechart.
You configure a transition or static reaction by combining one or more triggers, a guard, and an action into a logical sequence. For example, consider the following statement:
While in State 1: When the user presses the "Transfer" button and if the measured temperature is equal to or above 32 degrees Celsius, transfer the liquid from Container A to Container B.
The following table shows how this statement forms the logic of a transition.
|Phrase||Element of Transition Logic|
|When the user presses the "Transfer" button||Trigger|
|if the measured temperature is equal to or above 32 degrees Celsius||Guard|
|transfer the liquid from Container A to Container B.||Action|
In the LabVIEW Statechart Module, you write LabVIEW block diagram code to express each element of the transition logic.