Main Content

Debug SimEvents Models

A breakpoint is a point of interest in the simulation at which the debugger can suspend the simulation. SimEvents® Debugger allows you to inspect entities, set breakpoints based on entities leaving or entering storage elements, and step to events.

To enable debugging for a SimEvents model, add the SimEvents Debugger block to the model. When you click Step Forward in the Simulink® Toolstrip, the SimEvents Debugger displays.

SimEvents Debugger window containing an Explorer pane on the left with a search field. An Inspector section on the right side of the pane displays data for the element selected on the left.

The Explorer pane contains these nodes:

  • Event calendar — Maintains a list of current and pending events for the model. Select the Break before event execution check box to display event breakpoints on the Breakpoints node.

  • Breakpoints — Lists the breakpoints previously set for the model. You can view breakpoints set for the block, on event calendar, and for watched entities.

  • Storage — Displays the entity inspector listing all the storage blocks in the model and check boxes that let you select breakpoints. Blocks that contain entities are denoted with Circle filled in with blue color..

    To set breakpoints for post entry and pre-exit of entities, select the PostEntry Break and PreExit Break check boxes.

  • Entity Queue — Displays the entity inspector listing the entities and attributes associated with that block.

SimEvents Debugger is used in the Modeling Hybrid Systems - Tank Filling example to step through the model simulation, to set breakpoints, and to explore the event calendar.

The SimEvents software also provides an API that helps you to create your own visualization and debugging tools. For more information, see Use SimulationObserver Class to Monitor a SimEvents Model.

Start the Debugger

  1. Open the Modeling Hybrid Systems - Tank Filling example.

  2. Into the Simulink editor, add the SimEvents Debugger block at the top of the Tank Filling Station model.

  3. To start the debugger, in the Simulink editor toolstrip, click the Step Forward button.

    The debugger displays in a paused state.

  4. To step to the next event, click Green arrow with a long vertical tail pointing right to a sheet of paper..

    Note

    You can also click Continue (Dark green arrowhead pointing right within a light green circle.) to have the debugger continue the simulation. However, doing so without setting breakpoints causes the simulation to complete and the debugger to close.

  5. The debugger pauses at the next event and displays it in the event calendar. The current event is highlighted in green.

    SimEvents Debugger window showing a blue circle on the left of the "Fill This Tank" storage element. In the Event Calendar Events pane on the right, two events are listed at the Entity Queue and Tank Generator blocks. The event at the Entity Queue is highlighted in green.

Step Through Model

  1. To look at the current and scheduled events, click the Event calendar1 item. To set breakpoints, you can select the Break before event execution check box. The debugger hits the breakpoint before the next scheduled event. This breakpoint is for any event type, including Forward, Generate, ServiceComplete, Gateway, Destroy, and Trigger. Do not select this check box now.

    SimEvents Debugger window showing a blue circle on the left of the "Fill This Tank" storage element. In the Event Calendar Events pane on the right, two events are listed at the Entity Queue and Tank Generator blocks. The SimEvents Debugger is paused, and the event at the Entity Queue is highlighted in green.

  2. To inspect the attributes of an entity, click the Fill This Tank storage element in the Explorer pane.

    The Explorer pane of the SimEvents Debugger window showing the "Fill This Tank" storage element selected, as indicated by the light grey background. In the Inspector pane on the right, the attributes of "Fill This Tank" are listed: sys.id is 1, sys.priority is 300, Capacity is 300 and id is 1.

  3. The Inspector pane shows a table with the entity sys.id. To track the entity as the model simulates, click the associated check box.

  4. To set breakpoints for when this entity enters and leaves the block, at the bottom of the Inspector pane, select the two check boxes Break upon entity entry and Break prior to entity exit.

    Alternatively, to set the breakpoints on storage blocks all at once, click the Storage item in the Explorer pane. Notice that the Fill This Tank block is highlighted because it contains entities.

    Select the PostEntry Break check boxes for the blocks you want in this table.

  5. To progress to the next event, click Green arrow with a long vertical tail pointing right to a sheet of paper..

  6. Click Continue. Simulation continues until the next PostEntry or PreExit event.

    The same SimEvents Debugger window overlapping the Tank Filling Station block diagram. In this block diagram, the Fill This Tank block is highlighted in blue.

    The block associated with the breakpoint is highlighted.

  7. Step to the next event.

    The Event Calendar Events pane of the SimEvents Debugger window highlighting the current event of Type ServiceComplete at the Fill This Tank block.

    The next breakpoint at which the debugger stops is highlighted in the event calendar.

  8. Continue the simulation.

    The Inspector pane of the SimEvents Debugger displaying attributes of entities with IDs 1, 2 and 3.

    The simulation stops at the entity you opted to watch. As you continue the simulation or step through the model, the debugger stops at the various breakpoints and watchpoints that you set, letting you explore the model simulation.

  9. To inspect the entities in a currently selected block in the model, select the block in the model, then click the Inspect GCB button (Icon of block with one input and output port.).

    The Inspector pane displays the current details of the entities in this block.

    The Tank Filling Station block diagram overlapping the SimEvents Debugger window. In the block diagram, the Waiting Queue block is highlighted in blue. The details of the entities within this block are displayed in the Inspector pane on the right.

    You can continue to set entity watchpoints and event breakpoints.

To list select blocks, events, or entities, type their names in the search boxes at the top of the Explorer or Inspector panes.

The SimEvents software also provides a programmatic interface that lets you create your own simulation observer or debugger. For more information, see Create Custom Visualization.

See Also

Related Topics