Main Content

simulink.event.InputWriteLost

Trigger event when input port value update overwrites unprocessed data

Since R2022b

    Description

    Use a simulink.event.InputWriteLost object to configure a root input port to trigger a schedule event each time a value update on the input port overwrites unprocessed data. By configuring event triggers on input ports, you can model and simulate quality of service effects.

    You can trigger one or more model partitions in a rate-based system based on the flow of data into an input port in the top model or on a model reference interface. The EventTriggers parameter of an Inport or In Bus Element block stores the event trigger objects associated with the port. Each event trigger maps an input event to the name of the schedule event it triggers. The schedule for the model specifies the partition to execute in response to the schedule event. The table summarizes the event triggers you can configure on input ports. For each input port, you can configure one event trigger for each input event.

    Input EventInput Event DescriptionEvent Trigger Object
    Input writeValue for input port updates.simulink.event.InputWrite
    Input write timeoutInput port value does not update within a specified amount of time.simulink.event.InputWriteTimeout
    Input write lostInput port value update overwrites unprocessed data.simulink.event.InputWriteLost

    To configure the schedule for your model, use the Schedule Editor.

    Creation

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

    • When you configure an event trigger programmatically, create and configure the event trigger object yourself using the simulink.event.InputWriteLost function.

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

    Description

    writeLost = simulink.event.InputWriteLost creates the event trigger writeLost that you can use to configure an input port to trigger a specified schedule event each time an update of the input port value overwrites unprocessed data.

    example

    Properties

    expand all

    Event to trigger when input port value update overwrites unprocessed data, 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 InputWriteTimeout event trigger with the event name 'Auto', the software creates a schedule event that is scoped to the block. For example, for a block named Inport, the software creates the event Inport.InputWriteLost. Use the Schedule Editor to configure the listener for the event.

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

    Data Types: char | string

    Examples

    collapse all

    Configure a model to execute a partition each time an incoming value overwrites unprocessed data in a queue.

    Open the model SampleLost. The model contains the subsystem Sensors that models transmitting data from a single sensor every 0.1 seconds. A Queue block stores the sensor messages, and the model reference SinkSystem reads the sensor data from the queue. The model is configured to log events so you can visualize how messages propagate through the system using the Sequence Viewer.

    mdl = "SampleLost";
    open_system(mdl)

    The referenced model SinkSystem contains two subsystems:

    • The SignalConditioning subsystem receives messages of sensor data from the queue and scales the data using a Gain block.

    • The SampleLost subsystem contains a Constant block with a value of 1 connected to an Accumulator block.

    Configure the subsystem SignalConditioning as a periodic partition that receives a message from the queue every 0.5 seconds.

    1. In the Block Parameters dialog box or the Property Inspector, select Treat as atomic unit.

    2. From the Schedule as list, select Periodic partition.

    3. Specify the partition name as SignalConditioning.

    4. Specify the sample time as 0.5.

    Alternatively, use the set_param function to configure the TreatAsAtomicUnit, ScheduleAs, PartitionName, and SystemSampleTime parameters.

    load_system("SinkSystem");
    set_param("SinkSystem/SignalConditioning",...
        "TreatAsAtomicUnit","on",...
        "ScheduleAs","Periodic partition",...
        "PartitionName","SignalConditioning",...
        "SystemSampleTime","0.5");

    Configure the subsystem SampleLost as an aperiodic partition.

    1. In the Block Parameters dialog box or the Property Inspector, select Treat as atomic unit.

    2. From the Schedule as list, select Aperiodic partition.

    3. Specify the partition name as SampleLost.

    Alternatively, use the set_param function to configure the TreatAsAtomicUnit, ScheduleAs, and PartitionName parameters.

    set_param("SinkSystem/SampleLost",...
        "TreatAsAtomicUnit","on",...
        "ScheduleAs","Aperiodic partition",...
        "PartitionName","SampleLost")

    Configure the input port for the model reference SinkSystem with an input write lost event trigger.

    1. In the Block Parameters dialog box, on the Execution tab, click Add event trigger.

    2. From the list, select Input Write Lost.

    Alternatively, create and configure a simulink.event.InputWriteLost object. Then, configure the EventTriggers parameter of the input port using the set_param function.

    inLost = simulink.event.InputWriteLost;
    set_param("SinkSystem/Inport","EventTriggers",{inLost})

    Update the block diagram by pressing Ctrl+D or by using the set_param function. By default, the event trigger is configured to trigger the Auto event. When you update the block diagram or compile the model, the software creates the event SampleLost.Inport.InputWriteLost that is scoped to the Inport block in the model reference.

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

    Configure the model so the SampleLost.Inport.InputWriteLost event triggers the SampleLost partition.

    1. Open the Schedule Editor. In the model, click the badge on one of the partitioned subsystems. Alternatively, from the Block Parameters dialog box for the Inport block, on the Execution tab, click Open Schedule Editor.

    2. To expand the Events pane, click Expand Side .

    3. Select the SampleLost.Inport.InputWriteLost event. Then, drag it into the Schedule Editor canvas and release it on the SampleLost partition.

    Alternatively, use the get_param function to get the schedule for the model. Then, using the Order property of the schedule, specify the trigger for the SampleLost partition and use the set_param function to specify the modified schedule as the schedule for the model.

    sched = get_param(mdl,"Schedule");
    sched.Order.Trigger("SinkSystem.SampleLost") = "SinkSystem.Inport.InputWriteLost";
    set_param(mdl,"Schedule",sched)

    Simulate the model.

    out = sim(mdl);

    Use the Simulation Data Inspector and the Sequence Viewer to analyze how the sensor data moves through the system. On the Simulation tab, under Review Results, click Data Inspector and Sequence Viewer.

    To plot the data, display markers, and add cursors in the Simulation Data Inspector, load the view SampleLostView using the Simulink.sdi.loadView function.

    Simulink.sdi.loadView("SampleLostView.mldatx")

    Use the cursors to analyze the data.

    A sensor sample overwrites data in the queue for the first time when the sensor system writes the eleventh sample into the queue. The sensor writes into the queue before the sink system reads a value from the queue for the third time, so the queue size of 8 is no longer sufficient.

    The sink system reading the third value frees up space in the queue so no input write lost event occurs on the next time step, 1.1. Then, starting with time 1.2, four input write lost events occur in sequence as the sensor system continues writing values into the queue. The sink system pulls another value at time 1.5, freeing space in the queue. This pattern continues for the rest of the simulation.

    The sequence viewer denotes overwritten queue values with a closed black circle.

    Version History

    Introduced in R2022b