Skip to Main Content Skip to Search
Product Documentation

mdlSetInputPortSampleTime - Set the sample time of an input port that inherits its sample time from the port to which it is connected

Required

No

C Syntax

#define MDL_SET_INPUT_PORT_SAMPLE_TIME
void mdlSetInputPortSampleTime(SimStruct *S, int_T port,
 real_T sampleTime, real_T offsetTime)

C Arguments

S

SimStruct representing an S-Function block.

port

Index of a port.

sampleTime

Inherited sample time for port.

offsetTime

Inherited offset time for port.

MATLAB Syntax

SetInputPortSampleTime(s, port, time)

MATLAB Arguments

s

Instance of Simulink.MSFcnRunTimeBlock class representing the Level-2 MATLAB S-Function block.

port

Integer value specifying the index of port whose sampling mode is to be set.

time

Two-element array, [period offset], that specifies the period and offset of the times that this port samples its input.

Description

The Simulink engine invokes this method with the sample time that port inherits from the port to which it is connected.

For C MEX S-functions, if the inherited sample time is acceptable, this method sets the sample time of port to the inherited time, using ssSetInputPortSampleTime and ssSetInputPortOffsetTime. If the sample time is unacceptable, this method generates an error via ssSetErrorStatus. Note that any other input or output ports whose sample times are implicitly defined by virtue of knowing the sample time of the given port can also have their sample times set via calls to ssSetInputPortSampleTime or ssSetOutputPortSampleTime. This method is only valid for simulation, and must be enclosed in a #if defined(MATLAB_MEX_FILE) statement.

For Level-2 MATLAB S-functions, if the inherited sample time is acceptable, this method sets the sample time and offset time using the line

s.InputPort(port).SampleTime = time;

The engine calls this method until all input ports with inherited sample times are specified.

When inherited port-based sample times are specified, the sample time is guaranteed to be one of the following where 0.0 < period < inf and 0.0 <= offset < period.

 Sample TimeOffset Time
Continuous0.00.0
Discreteperiodoffset

Constant, triggered, and variable-step sample times are not propagated to S-functions with port-based sample times.

Generally mdlSetInputPortSampleTime is called once per port with the input port sample time. However, there can be cases where this function is called more than once. This happens when the simulation engine is converting continuous sample times to continuous but fixed in minor steps sample times. When this occurs, the original values of the sample times specified in mdlInitializeSizes are restored before this method is called again.

The final sample time specified at the port can be different from (but equivalent to) the sample time specified by this method. This occurs when

The S-function can examine the final sample times in mdlInitializeSampleTimes.

Languages

C, C++, MATLAB

See Also

ssSetInputPortSampleTime, ssSetOutputPortSampleTime, mdlInitializeSampleTimes

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS