MATLAB SIMULINK 7 - DEVELOPING S-FUNCTIONS Guide de l'utilisateur Page 69

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 210
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 68
Overview of the C MEX S-Function Routines
3-25
Note You cannot access the w ork, state, input, output, and other vectors in
this routine. Use this rou tine only to validate the parameters. Addition al
processing of the parameters should be done in mdlProcessParameters.
Example: mdlCheckParameters. This example checks the first S-function
parameter to verify that it is a real nonnegative scalar:
#define PARAM1(S) ssGetSFcnParam(S,0)
#define MDL_CHECK_PARAMETERS /* Change to #undef to remove function */
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
static void mdlCheckParameters(SimStruct *S)
{
if (mxGetNumberOfElements(PARAM1(S)) != 1) {
ssSetErrorStatus(S,”Parameter to S-function must be a scalar”);
return;
} else if (mxGetPr(PARAM1(S))[0] < 0) {
ssSetErrorStatus(S, “Parameter to S-function must be non-negative”);
return;
}
}
#endif /* MDL_CHECK_PARAMETERS */
In addition to the above routine, you must add a call to this routine from
mdlInitializSizes to check parameters during initialization since
mdlCheckParameters is only called while the simul ation is running. To do this,
in
mdlInitializeSizes, after setting the number of parameters you expect in
your S- function by using
ssSetNumSFcnParams,usethiscode:
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(ssGetErrorStates(S) != NULL) return;
} else {
return; /* Simulink will report a mismatch error. */
}
#endif
...
}
See matlabroot/simulink/src/sfun_errhdl.c for an example.
Vue de la page 68
1 2 ... 64 65 66 67 68 69 70 71 72 73 74 ... 209 210

Commentaires sur ces manuels

Pas de commentaire