eventTimer
Class: matlab.DiscreteEventSystem
Namespace: matlab
Create entity timer event
Syntax
event=eventTimer(tag,delay)
Description
creates an event to delay an entity for a period of time. You can then schedule the
timer by returning it as the output argument when implementing an event action method,
such as event
=eventTimer(tag
,delay
)entry
.
Input Arguments
tag
— Tag
character vector
Custom tag of this entity timer event.
delay
— Delay
double
Time delay between current simulation time and the time that this timer event will be executed.
Output Arguments
event
— Event
MATLAB® structure
Event that delays the entity in current event action context for a period of time.
Examples
Define Timer Event
Define a timer event.
function [entity,event] = entry(obj,storage,entity,src) % Define a timer event % - The event is regarding the entity in current event action context % - The event has a custom tag 'timeout' % - The event will be executed 3.0 seconds later event = obj.eventTimer('timeout', 3.0); end
Custom Block with Timer Events
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
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)