Working with SimEvents and Simulink

You can exchange data between SimEvents® and Simulink® environments. However, time-based signals and SimEvents signals have different characteristics.

Exchange Data Between SimEvents and Simulink

Use Simulink Function blocks in SimEvents models:

  • To read or write attributes of entities.

  • To send messages that trigger other events.

  • To exchange data between event and time domain sections of a model.

Use Message Send and Receive blocks to send and receive messages between Simulink and SimEvents blocks.

Time-Based Signals and SimEvents Block Transitions

Time-based signals and SimEvents signals have different characteristics. Here are some indications that a time-based signal is automatically converted into a SimEvents signal, or conversely:

  • You want to connect a time-based signal to an input port of a SimEvents block.

  • You are using data from a SimEvents block to affect time-based dynamics.

  • You want to perform a computation involving both time-based signals and SimEvents output.

When the transition occurs, a capital E appears on the line.

SimEvents Support for Simulink Subsystems

You can use SimEvents blocks (discrete-event blocks) without restriction in Simulink Virtual Subsystems, and in Simulink® Nonvirtual Subsystems, observing some specific guidelines.

For more information about Simulink subsystems, see Subsystem, Atomic Subsystem, Nonvirtual Subsystem, CodeReuse Subsystem.

Discrete-Event Blocks in Virtual Subsystems

You can use discrete-event blocks without restriction in a virtual subsystem.

Discrete-Event Blocks in Nonvirtual Subsystems

When you use discrete-event blocks in an atomic subsystem, follow these guidelines:

  • The entire discrete-event subsystem, which includes all discrete-event blocks, must reside entirely within the atomic subsystem. You cannot route entities into, or out of, the atomic subsystem.

  • If you want to connect two or more atomic subsystems that contain discrete-event blocks, each atomic subsystem must meet all the preceding conditions.

For more information about atomic subsystems, see Subsystem, Atomic Subsystem, Nonvirtual Subsystem, CodeReuse Subsystem.

Discrete-Event Blocks in Variant Subsystems

You can use discrete-event blocks in a variant subsystem. The software permits both entities and time-based signals to enter and depart a virtual variant.

However, if you use an atomic subsystem as a variant, or within a variant, then that atomic subsystem must obey the rules for using discrete-event blocks in nonvirtual subsystems. These rules are described in Discrete-Event Blocks in Nonvirtual Subsystems. An atomic subsystem is the only type of nonvirtual subsystem that can contain discrete-event blocks, even when the nonvirtual subsystem is contained within a variant subsystem.

The SimEvents software does not support setting the Variant activation time parameter to code compile for these blocks:

  • Variant Subsystem

  • Variant Sink

  • Variant Source

Save Simulation Data

Behavior of the To Workspace Block

The To Workspace block writes event-based signals to the MATLAB® workspace when the simulation stops or pauses. One-way to pause a running simulation is to select Pause under the Debug tab.

Send Queue Length to the Workspace

The example shows one way to write the times and values of signals to the MATLAB workspace. In this case, the signal is the n output from an Entity Queue block, which indicates how many entities the queue holds.

You can use different time formats in the To Workspace block to display the data.

To record entities and their attributes passing along an entity line, consider connecting a To Workspace block to that entity line.

Data Logging

You can log data from your SimEvents model using Simulink. For more information, see Save Run-Time Data from Simulation.

See Also

| |

Related Examples

More About