Main Content

simulink.event.InputWrite

Trigger schedule event when input port value updates

Since R2022b

    Description

    Use a simulink.event.InputWrite object to configure a root-level input port in a rate-based model to create a schedule event each time the value of the input port updates. You can model and simulate quality of service effects by using event triggers, such as the InputWrite object, to execute partitions in response to the flow of data into a model.

    Event triggers create schedule events based on the runtime activity at a particular location in the model. The schedule for the model determines which partitions execute in response to the schedule event as well as the event priority. To execute one or more partitions in response to the flow of data into a model, configure event triggers on one or more root-level input ports in the model. To configure the schedule for your model, use the Schedule Editor.

    The Events parameter of an Inport or In Bus Element block stores the event triggers associated with the port. Each event trigger maps an input event related to the flow of data into the port to the name of the schedule event to trigger. The table summarizes the event triggers you can configure on root-level input ports. You can configure an input port with one event trigger for each input event.

    Input EventInput Event DescriptionEvent Trigger Object
    Input writeAn input write event occurs each time the input port value updates.simulink.event.InputWrite
    Input write timeoutAn input write timeout event occurs each time the input port value does not update within a specified amount of time.simulink.event.InputWriteTimeout
    Input write lostAn input write lost event occurs each time a new input port value overwrites unprocessed data.simulink.event.InputWriteLost

    Creation

    You can configure the event triggers for an input port programmatically or interactively.

    • When you configure the input port programmatically, create and configure the event trigger object yourself using the simulink.event.InputWrite function.

    • When you configure the input port interactively using the Block Parameters dialog box or the Property Inspector, the software creates and configures the event trigger object.

    Description

    inputWrite = simulink.event.InputWrite creates the event trigger object inputWrite that you can use to configure an input port to trigger a specified schedule event each time the port value updates.

    example

    Properties

    expand all

    Event to trigger when input port value updates, specified as a string or a character vector. The event name must be 'Auto' or the name of an event defined in the Schedule Editor.

    By default, the event name is 'Auto'. When you update or compile a model that has an input port configured with an InputWrite event trigger with the event name 'Auto', the software:

    1. Creates a schedule event that is scoped to the block. For example, for a block named Inport, the software creates the event Inport.InputWrite.

      This event appears in the Events panel in the Schedule Editor with other events defined for the model.

    2. Configures the listener for the event as the aperiodic partition connected to the input port, if the input port is connected to an aperiodic partition.

      To configure a different listener for the event, use the Schedule Editor.

    Example: inWrite.EventName = "myEvent" configures the event trigger object inWrite to trigger the event myEvent that is defined in the Schedule Editor.

    Data Types: char | string

    Examples

    collapse all

    Open the model ScaleInput. The model loads external input data into a subsystem. The subsystem contains a Gain block that multiplies the subsystem input by two.

    mdl = "ScaleInput";
    open_system(mdl)

    Create a timeseries object with input data for the model. The input data represents a line with a slope of one sampled every second for ten seconds.

    sampleTime = 1;
    numSteps = 11;
    time = sampleTime*(0:numSteps-1);
    time = time';
    
    data = time;
    
    lineTS = timeseries(data,time);

    Configure the model to load the timeseries object.

    set_param(mdl,"LoadExternalInput","on")
    set_param(mdl,"ExternalInput","lineTS")

    Simulate the model. By default, the maximum step size for the simulation is calculated such that the simulation takes 50 steps, resulting in a time step every 0.2 seconds.

    out = sim(mdl);

    Configure the model to execute the partition only when the value of the input port updates.

    Configure the subsystem to execute as an aperiodic partition. In the Block Parameters dialog box or the Property Inspector, select Treat as atomic unit, then from the Schedule as list, select Aperiodic partition. Alternatively, use the set_param function to configure the TreatAsAtomicUnit and ScheduleAs parameters.

    set_param("ScaleInput/Subsystem","TreatAsAtomicUnit","on")
    set_param("ScaleInput/Subsystem","ScheduleAs","Aperiodic partition")

    Add an input write event trigger to the Inport block. In the Block Parameters dialog box, on the Execution tab, click Add event trigger , then select Input Write from the list. Alternatively, create a simulink.event.InputWrite object and use the set_param function to configure the EventTriggers parameter.

    inputWrite = simulink.event.InputWrite;
    set_param("ScaleInput/Inport","EventTriggers",{inputWrite})

    Update the block diagram by pressing Ctrl+D or by using the set_param function. By default, the input write event trigger is configured to trigger the Auto event. When you update the block diagram or compile the model, the software creates the event Inport.InputWrite that is scoped to the Inport block and configures the partition connected to the Inport block as the listener for the event.

    set_param(mdl,"SimulationCommand","update")

    Simulate the model again. Because input port data drives the partition execution, the simulation takes a step only when the input value updates.

    out = sim(mdl);

    Version History

    Introduced in R2022b