ssGetOutputPortSampleTimeIndex
Get sample time index of output port
Syntax
int_T ssGetOutputPortSampleTimeIndex(SimStruct *S, int_T outputPortIdx)
Arguments
S
SimStruct that represents an S-Function block.
outputPortIdx
Index of the output port whose sample time index is to be returned.
Returns
An int_T
value indicating the sample time index for the output
port specified by the index outputPortIdx
. Returns
CONSTANT_TID
(-2
) for constant
(inf
) sample times.
Description
Use in any routine after sample time propagation (i.e., in or after
mdlInitializeSampleTimes
) 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 by
ssGetOutputPortSampleTimeIndex
and the task ID
(tid
) passed into the S-function by the Simulink engine are not equivalent. Use the index returned by
ssGetOutputPortSampleTimeIndex
in calls to
ssIsSampleHit
, etc., to determine if the S-function is
running at one of its sample rates. For example, the following
mdlOutputs
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 of CONSTANT_TID
(-2
) for constant (inf
) sample times. In
this case, the sample time index and model-wide task ID are identical.
Languages
C, C++
Examples
See the S-function sfun_multirate.c
used in sfcndemo_sfun_multirate
.
Version History
Introduced in R2008a