Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Contents

ssGetInputPortSampleTimeIndex

Get the sample time index of an input port

Syntax

int_T ssGetInputPortSampleTimeIndex(SimStruct *S,
 int_T inputPortIdx)

Arguments

S

SimStruct representing an S-Function block.

inputPortIdx

Index of the input port whose sample time index is to be returned.

Returns

An int_T value indicating the sample time index of the input port specified by the index inputPortIdx. 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 input 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 ssGetInputPortSampleTimeIndex and the task ID (tid) passed into the S-function by the Simulink engine are not equivalent. Use the index returned by ssGetInputPortSampleTimeIndex 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 checks if the sample time index for the first input port is executing.

static void mdlOutputs(SimStruct *S, int_T tid)
{
   int sti = ssGetInputPortSampleTimeIndex(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++

Was this topic helpful?