ssEnableSystemWithTid
Enable a function-call subsystem connected to this S-function
Syntax
int_T ssEnableSystemWithTid(SimStruct *S, int_T element, int_T tid)
Arguments
S
SimStruct that represents an S-Function block.
element
Index of the output port element corresponding to the function-call subsystem.
tid
Task ID.
Returns
An int_T
1
if successful; otherwise, 0
.
Description
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*/ return; }
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.
Languages
C, C++
Examples
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
callback first specifies that the
S-function explicitly enables and disables the function-call subsystem. The
mdlInitializeSampleTimes
callback
then handles the actual enabling and disabling of the function-call subsystem in
order to reset the states.mdlOutputs
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 */ ssSetExplicitFCSSCtrl(S,1); /* Call function-call subsystem on first element */ ssSetCallSystemOutput(S,0); ssSetModelReferenceSampleTimeDefaultInheritance(S); } /* 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)) { return; } } /* Call function-call subsystem */ if (!ssCallSystemWithTid(S,0,tid)) { return; } /* Disable/re-enable function-call subsystem when time = 10 */ if (t==10) { if (!ssDisableSystemWithTid(S,0,tid)) { return; } if (!ssEnableSystemWithTid(S,0,tid)) { return; } } y[0] = x[0]; } /* End mdlOutputs */
Version History
Introduced before R2006a