timer
Class: matlab.DiscreteEventSystem
Namespace: matlab
Event action when timer completes
Syntax
[entity,events]=timer(obj,storage,entity,tag)
[entity,events,out1,...]=timer(obj,storage,entity,tag,in1,...)
Description
Input Arguments
Discrete-event System object.
Index of the storage element.
Entity for the timer event. Entity has these fields:
sys(MATLABstructure) — It has these fields:id(double) — Entity IDpriority(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
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 eventdelay(double) — Delay before the eventpriority(double) — Priority of the eventStorage(double) — Index of the storage elementtag(character vector) — Event taglocation(MATLABstructure) — Source or destination location of entity
Data outputs of the object. You must specify these output arguments when the object has data outputs.
Examples
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
This example uses a custom entity storage block with one
input, two outputs, and a storage element. An entity of type
Part with TimeOut attribute enters the
storage of the custom block to be processed. TimeOut
determines the maximum allowed processing time of the parts. When a part enters
the storage, two timer events are activated. One timer tracks the processing
time of the part in the oven. When this timer expires, the entity is forwarded
to output 1. Another timer acts as a fail-safe and tracks if
the maximum allowed processing time is exceeded or not. When this timer expires,
the process is terminated and the entity is forwarded to the output
2.
For more information, see Custom Entity Storage Block with Multiple Timer Events.
classdef CustomEntityStorageBlockTimer < matlab.DiscreteEventSystem % A custom entity storage block with one input port, two output ports, and one storage. % Nontunable properties properties (Nontunable) % Capacity Capacity = 1; end methods (Access=protected) function num = getNumInputsImpl(~) num = 1; end function num = getNumOutputsImpl(~) num = 2; end function entityTypes = getEntityTypesImpl(obj) entityTypes = obj.entityType('Part'); end function [inputTypes,outputTypes] = getEntityPortsImpl(obj) inputTypes = {'Part'}; outputTypes = {'Part' 'Part'}; end function [storageSpecs, I, O] = getEntityStorageImpl(obj) storageSpecs = obj.queueFIFO('Part', obj.Capacity); I = 1; O = [1 1]; end end methods function [entity,event] = PartEntry(obj,storage,entity,source) % Specify event actions when entity enters storage. ProcessingTime=randi([1 15]); event1 = obj.eventTimer('TimeOut', entity.data.TimeOut); event2 = obj.eventTimer('ProcessComplete', ProcessingTime); event = [event1 event2]; end function [entity, event] = timer(obj,storage,entity,tag) % Specify event actions for when scheduled timer completes. event = obj.initEventArray; switch tag case 'ProcessComplete' event = obj.eventForward('output', 1, 0); case 'TimeOut' event = obj.eventForward('output', 2, 0); end end end end
Version History
Introduced in R2016a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)