timer

Class: matlab.DiscreteEventSystem
Package: matlab

Event action when timer completes

Syntax

[entity,events]=timer(obj,storage,entity,tag)
[entity,events,out1,...]=timer(obj,storage,entity,tag,in1,...)

Description

[entity,events]=timer(obj,storage,entity,tag) specifies event actions for when scheduled timer completes.

[entity,events,out1,...]=timer(obj,storage,entity,tag,in1,...) specifies such event actions when the block has one or more input signal ports and/or signal output ports.

Input Arguments

expand all

Discrete-event System object.

Index of the storage element.

Entity for the timer event. Entity has these fields:

  • sys (MATLAB structure) — It has these fields:

    • id (double) — Entity ID

    • priority (double) — Entity priority

  • data — Entity data

Tag of the currently executing timer event.

Any data inputs of the object. These input arguments exist only when the object has data inputs.

Output Arguments

expand all

Entity with changed value.

Events to be scheduled after the method returns. Use matlab.DiscreteEventSystem class methods to create events. Each event has these fields:

  • type (character vector) — Type of the event

  • delay (double) — Delay before the event

  • priority (double) — Priority of the event

  • Storage (double) — Index of the storage element

  • tag (character vector) — Event tag

  • location (MATLAB structure) — Source or destination location of entity

Data outputs of the object. You must specify these output arguments when the object has data outputs.

Examples

expand all

Forward entity when timer completes for discrete-event system object obj.

function [entity,events] = timer(obj,storage,entity,tag)
    % Check which timer of the entity has expired, and forward the
    % entity to the next location accordingly.
    switch tag
        case 'ServiceComplete'
            entity.done = 1;
            events = obj.eventForward('output', 1, 0);                    
        case 'Timeout'
            entity.done = 0; 
            events = obj.eventForward('storage', 2, 0);
    end
end

Introduced in R2016a