Main Content

simulink.event.InputWriteTimeout

Trigger event when input port value does not update within specified time

Since R2022b

    Description

    Use a simulink.event.InputWrite object to configure a root input port to trigger a schedule event when the input port value does not update within a specified amount of time. 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.InputWriteTimeout 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

    example

    writeTimeout = simulink.event.InputWriteTimeout creates the event trigger writeTimeout that you can use to configure an input port to trigger a specified schedule event each time the input port value does not update within the specified amount of time.

    Properties

    expand all

    Event to trigger when input port value does not update within specified time, 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.InputWriteTimeout. Use the Schedule Editor to configure the listener for the event.

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

    Data Types: char | string

    Time limit for update of input port value, specified as a string or a character vector that defines a positive numeric value.

    Example: inTimeout.Timeout = "1" configures the event trigger object inTimeout with a timeout of one second.

    Data Types: char | string

    Examples

    collapse all

    Configure a model to execute a partition when the input value does not update within ten seconds.

    Open the model InputTimeout. The model contains an input port that loads external data into two subsystems.

    mdl = "InputTimeout";
    open_system(mdl);

    Configure the model to allow multiple partitions to access the model inputs and outputs. Both subsystems need to use the input port value, and each subsystem will execute at its own rate.

    1. On the Modeling tab, under Setup, click Model Settings.

    2. In the Configuration Parameters dialog box, on the Solver pane, expand Solver details.

    3. Under Tasking and sample time options, select Allow multiple tasks to access inputs and outputs.

    Alternatively, use the set_param function to configure the AllowMultiTaskInputOutput parameter.

    set_param(mdl,"AllowMultiTaskInputOutput","on")

    Configure the subsystem SampleSignal as a periodic partition that samples the input signal every second.

    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 SampleSignal.

    4. Specify the sample time as 1.

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

    set_param("InputTimeout/SampleSignal","TreatAsAtomicUnit","on",...
        "ScheduleAs","Periodic partition",...
        "PartitionName","SampleSignal",...
        "SystemSampleTime","1")

    Configure the subsystem InputTimeout 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 InputTimeout.

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

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

    Configure the input port with an input write timeout event trigger.

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

    2. From the list, select Input Write Timeout.

    3. In the Timeout column of the table, specify the timeout as 10.

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

    inTimeout = simulink.event.InputWriteTimeout;
    inTimeout.Timeout = "10";
    set_param("InputTimeout/Inport","EventTriggers",{inTimeout})

    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 Inport.InputWriteTimeout that is scoped to the Inport block.

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

    Configure the model schedule such that the Inport.InputWriteTimeout event triggers the InputTimeout 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 Inport.InputWriteTimeout event. Then, drag it into the Schedule Editor canvas and release it on the InputTimeout partition.

    In the Schedule Editor, click Update Diagram. The block diagram updates to reflect the binding of the Inport.InputWriteTimeout event to the InputTimeout 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 InputTimeout 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("InputTimeout") = "Inport.InputWriteTimeout";
    set_param(mdl,"Schedule",sched)

    Create a timeseries object that contains input data with sample values separated by an increasing time interval.

    time = [0 1 3 5 8 13 21 34 55 89 144];
    data = (0:10)';
    inp = timeseries(data,time);

    Configure the model to load the input data.

    set_param(mdl,"LoadExternalInput","on",...
        "ExternalInput","inp")

    Simulate the model.

    out = sim(mdl);

    The InputTimeout partition executes only when the input value does not update for at least ten seconds.

    Version History

    Introduced in R2022b