ssGetOutputPortSampleTimeIndex
Get sample time index of output port
Syntax
int_T ssGetOutputPortSampleTimeIndex(SimStruct *S, int_T outputPortIdx)
Arguments
-
S
-
SimStruct representing an S-Function block.
-
outputPortIdx
-
Index of the output port whose sample time index is to be returned.
Returns
Anint_T
value indicating the sample time index for the output port specified by the indexoutputPortIdx
. ReturnsCONSTANT_TID
(-2
) for constant (inf
) sample times.
Description
Use in any routine after sample time propagation (i.e., in or aftermdlInitializeSampleTimes
) to determine the sample time index of an output port. You should use this macro only if you have specified port-based sample times.
The Simulink®engine returns the sample time index in the context of the S-function's sample times, not the entire model's sample times. Consequently, the sample time index (sti
) returned byssGetOutputPortSampleTimeIndex
and the task ID (tid
) passed into the S-function by the Simulink engine are not equivalent. Use the index returned byssGetOutputPortSampleTimeIndex
in calls tossIsSampleHit
, etc., to determine if the S-function is running at one of its sample rates. For example, the followingmdlOutputs
method uses the sample time index to check if the first output port is executing.
static void mdlOutputs(SimStruct *S, int_T tid) { int sti = ssGetOutputPortSampleTimeIndex(S,0); if (ssIsSampleHit(S, sti, tid)) {CodeForThisSampleRateHere()} }
The Simulink engine returns an index ofCONSTANT_TID
(-2
) for constant (inf
) sample times. In this case, the sample time index and model-wide task ID are identical.
语言
C, C++
Example
See the S-functionsfun_multirate.c
used insfcndemo_sfun_multirate
.