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 representing an S-Function block.
-
element
-
Index of the output port element corresponding to the function-call subsystem.
-
tid
-
Task ID.
Returns
Anint_T
1
if successful; otherwise,0
.
Description
Use inmdlOutputs
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. SeessSetExplicitFCSSCtrl
for more information. If the S-function has not done this, invokingssEnableSystemWithTid
results in an error.
The effect of invoking this function depends on the setting of theStates when enabling parameterof the function-call subsystem'sTriggerblock. If the parameter is set toreset
,这个函数调用函数调用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.,Integratorblocks, to their initial values. Thus, if the Trigger block'sStates when enablingoption is set toreset
, invoking this function effectively resets the states of the function-call subsystem. If the Trigger block'sStates when enablingoption is set toheld
, this function simply invokes the subsystem's enable method, without invoking its initialize method and hence without resetting its states.
语言
C, C++
Example
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. ThemdlInitializeSampleTimes
callback then handles the actual enabling and disabling of the function-call subsystem in order to reset the states.mdlOutputs
The following code inmdlInitializeSampleTimes
usesssSetExplicitFCSSCtrl
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 */
ThemdlOutputs
callback is shown below. It first usesssEnableSystemWithTid
to enable the function-call subsystem at the beginning of the simulation. The function-call subsystem must be enabled before it can be called usingssCallSystemWithTid
. After the simulation has run for 10 seconds, themdlOutputs
callback invokesssDisableSystemWithTid
to disable the function-call subsystem. By invokingssEnableSystemWithTid
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 */