Control Output Switch with Event Actions and Simulink Function
This example shows how to change the selected output port of an Entity Output Switch block to route entities along different paths where a path is selected on a per-entity basis, not on a predetermined time schedule.
Control Output Switch with a Simulink Function Block
The following example illustrates a scenario in which the Entity Output Switch block is controlled by the Simulink Function block.
Double-click the function signature on the Simulink Function block and enter
Double-click the Simulink Function block. Add a Repeating Sequence Stair block, and set its Sample time parameter to
-1(inherited), a Message Send block and an Out1 block. Connect the blocks as shown.
In the Repeating Sequence Stair block, set the Vector of output values to
[3 2 1].
When the Simulink Function block executes, it outputs the next number from a repeating sequence and Message Send block outputs message values
1based on the sequence of values specified in the Repeating Sequence Stair block.
In the Entity Server block, in the Exit action field enter this code.
When service in the Entity Server block is complete, the entity
exits the block and advances to the Entity Output Switch block. The
departure of the entity from the Entity Server block calls the
SwitchCtrl() function which activates the Simulink
Function block. Then the output message of the Simulink
Function block determines which output port the entity uses when it
departs the Entity Output Switch block.
Specify an Initial Port Selection
When the Entity Output Switch block uses an input message, the block might attempt to use the message before its first sample time hit. If the initial value of the message is out of range (for example, it is unavailable). You should then specify the initial port selection in the Entity Output Switch block's dialog box. To achieve this, you can follow these steps.
In the Entity Output Switch, select
From control portas the Switching criterion.
Set Initial port selection to the desired initial port. The value must be an integer between 1 and Number of output ports. The Entity Output Switch block uses Initial port selection until the first control port message arrives.
Entity Input Switch | Entity Output Switch | Entity Replicator | Entity Gate
- Route Vehicles Using an Entity Output Switch Block
- Serve High-Priority Customers by Sorting Entities Based on Priority
- Model Traffic Intersections as a Queuing Network
- Enable a Gate for a Time Interval