Main Content

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, C++

Syntax

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

Arguments

S

SimStruct representing an S-Function block.

port

Index of a port.

sampleTime

Inherited sample time forport.

offsetTime

Inherited offset time forport.

Description

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

对于C MEX S函数,如果可以接受遗传的样本时间,则此方法设置了样本时间portto the inherited time, usingssSetInputPortSampleTimeandssSetInputPortOffsetTime. If the sample time is unacceptable, this method generates an error viassSetErrorStatus. 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 tossSetInputPortSampleTimeorssSetOutputPortSampleTime. This method is only valid for simulation, and must be enclosed in a#if defined(MATLAB_MEX_FILE)statement.

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 where0.0< period < infand0.0<= offset < period.

Sample Time Offset Time
Continuous 0.0 0.0
Discrete period offset

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

GenerallymdlSetInputPortSampleTimeis 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 inmdlInitializeSizesare 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 model uses a fixed-step solver and the port has a continuous but fixed in minor step sample time. In this case, the Simulink engine converts the sample time to the fundamental sample time for the model.

  • The engine adjusts the sample time to be as numerically sound as possible. For example, the engine converts[0.2499999999999, 0]to(0.25, 0).

The S-function can examine the final sample times inmdlInitializeSampleTimes.

Introduced before R2006a