This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Enable a function-call subsystem connected to this S-function


int_T ssEnableSystemWithTid(SimStruct *S, int_T element, int_T tid)



SimStruct representing an S-Function block.


Index of the output port element corresponding to the function-call subsystem.


Task ID.


An int_T 1 if successful; otherwise, 0.


Use in mdlOutputs to enable a function-call subsystem connected to the S-function. The invoking syntax is

if (!ssEnableSystemWithTid(S, element, tid)) {
  /* Error occurred which will be reported by the Simulink engine*/

    Note   Before invoking this function, the S-function must have specified that it explicitly enables and disables the function-call subsystems that it calls. See ssSetExplicitFCSSCtrl for more information. If the S-function has not done this, invoking ssEnableSystemWithTid results in an error.

The effect of invoking this function depends on the setting of the States when enabling parameter of the function-call subsystem's Trigger block. If the parameter is set to reset, this function invokes the function-call subsystem's initialize method and then its enable method. The subsystem's initialize and enable methods in turn invoke the initialize and enable methods of any blocks in the subsystem that have these methods. Initialize methods reset the states of blocks that have states, e.g., Integrator blocks, to their initial values. Thus, if the Trigger block's States when enabling option is set to reset, invoking this function effectively resets the states of the function-call subsystem. If the Trigger block's States when enabling option is set to held, this function simply invokes the subsystem's enable method, without invoking its initialize method and hence without resetting its states.


C, C++


This example shows how to configure an S-function to reset the states of the function-call subsystem it calls. The code below shows the macros needed in two callbacks. The mdlInitializeSampleTimes callback first specifies that the S-function explicitly enables and disables the function-call subsystem. The mdlOutputs callback then handles the actual enabling and disabling of the function-call subsystem in order to reset the states.

The following code in mdlInitializeSampleTimes uses ssSetExplicitFCSSCtrl to enable the S-function to explicitly enable and disable the function-call subsystem. ssSetCallSystemOutput then specifies that the function-call subsystem is invoked by the first element of the S-function's first output port.

static void mdlInitializeSampleTimes(SimStruct *S)
    ssSetSampleTime(S, 0, 0.1);
    ssSetOffsetTime(S, 0, 0.0);

    /* Explicitly enable/disable function-call subsystem */

    /* Call function-call subsystem on first element */


} /* End mdlInitializeSampleTimes */

The mdlOutputs callback is shown below. It first uses ssEnableSystemWithTid to enable the function-call subsystem at the beginning of the simulation. The function-call subsystem must be enabled before it can be called using ssCallSystemWithTid. After the simulation has run for 10 seconds, the mdlOutputs callback invokes ssDisableSystemWithTid to disable the function-call subsystem. By invoking ssEnableSystemWithTid again, the function-call subsystem is re-enabled and the states are reset.

static void mdlOutputs(SimStruct *S, int_T tid)
    real_T  *x = ssGetRealDiscStates(S);
    real_T  *y = ssGetOutputPortRealSignal(S,1);
    time_T   t = ssGetT(S); /* Simulation time */

    /* Enable function-call subsystem at start of simulation */
    if (t==0) {
        if (!ssEnableSystemWithTid(S,0,tid)) {
    /* Call function-call subsystem */
    if (!ssCallSystemWithTid(S,0,tid)) {

    /* Disable/re-enable function-call subsystem when time = 10 */
    if (t==10) {
        if (!ssDisableSystemWithTid(S,0,tid)) {
        if (!ssEnableSystemWithTid(S,0,tid)) {
    y[0] = x[0];

} /* End mdlOutputs */

Introduced before R2006a

Was this topic helpful?