mdlCheckParameters
Check the validity of a C MEX S-function's parameters
Required
No
Languages
C, C++
Syntax
#define MDL_CHECK_PARAMETERSvoid mdlCheckParameters(SimStruct *S)
Arguments
-
S
-
SimStruct representing an S-Function block.
Description
Verifies new parameter settings whenever parameters change or are reevaluated during a simulation. If you have金宝app®Coder™C,墨西哥人-functions, this method is only valid for simulation, and must be enclosed in a#if defined(MATLAB_MEX_FILE)
语句与支持非线s功能的代码生成目标兼容。金宝app
When a simulation is running, changes to S-function parameters can occur at any time during the simulation loop, that is, either at the start of a simulation step or during a simulation step. When the change occurs during a simulation step, the Simulink engine calls this routine twice to handle the parameter change. The first call during the simulation step is used to verify that the parameters are correct. After verifying the new parameters, the simulation continues using the original parameter values until the next simulation step, at which time the new parameter values are used. Redundant calls are needed to maintain simulation consistency.
Note
You cannot access the work, state, input, output, and other vectors in this routine. Use this routine only to validate the parameters. Additional processing of the parameters should be done inmdlProcessParameters
.
Example
This example checks the first S-function parameter to verify that it is a real nonnegative scalar.
Note
SincemdlCheckParameters
is an optional method, a#define MDL_CHECK_PARAMETERS
statement precedes the function. Also, since theSimulink Coderproduct does not support code generation formdlCheckParameters
, the function is wrapped in a#if defined(MATLAB_MEX_FILE)
statement.
#define param1(s)ssgetsfcnparam(s,0)#define mdl_check_parameters / *更改为#undef以删除函数 * / #if定义(MDL_CHECK_PARAMETERS)&&定义(MATLAB_MEX_FILE)(MATLAB_MEX_FILE)静态void mdlcheckparameters(simscarters(simstrument *s)param1(s))!= 1){sssetErrorStatus(s,“参数到s函数必须为标量”);返回;} else if(mxgetpr(param1(s))[0] <0){sssetErrorStatus(s,“到s-函数的参数必须是非负”);返回;}} #endif / * mdl_check_parameters * /
In addition to the preceding routine, you must add a call to this method frommdlInitializeSizes
to check parameters during initialization, becausemdlCheckParameters
is only called while the simulation is running. To do this, after setting the number of parameters you expect in your S-function by usingssSetNumSFcnParams
, use this code inmdlInitializeSizes
:
static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 1); /* Number of expected parameters */ #if defined(MATLAB_MEX_FILE) if(ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S) { mdlCheckParameters(S); if(ssGetErrorStatus(S) != NULL) return; } else { return; /* The Simulink engine reports a mismatch error. */ } #endif...}
Note
The macrossGetSFcnParamsCount
returns the actual number of parameters entered in the dialog box.
Seesfun_errhdl.c
for an example.