mdlStart is not called during the execution of s-function

9 次查看(过去 30 天)
It seems even though I have added #define MDL_START rutine in s-function, the mdlStart function is not called. The result is that whole Matlab crashes when I start the simulink model.
I have added the ssPrintf in mdlStart to see if the function is called and I never get the message in the command window. It is strange that even if I add the ssPrintf in the mdlTerminate I also do not see the message in the command window. ssPrintf works in mdlOutputs function.
I am adding the code
#define S_FUNCTION_NAME test8 /* Defines and Includes */
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"
#include "matrix.h"
#include "mex.h"
mxArray *array_ptr;
static void mdlInitializeSizes(SimStruct *S)
{
// nothing special here
}
static void mdlInitializeSampleTimes(SimStruct *S)
{
// nothing special here
}
#define MDL_START
#if defined(MDL_START)
static void mdlStart(SimStruct *S)
{
ssPrintf("mdlStart\n");
array_ptr = mexGetVariable("global", "testVar");
if (array_ptr == NULL ) {
array_ptr=mxCreateDoubleMatrix(1,1,mxREAL);
}
mxGetPr(array_ptr)[0]=0;
}
#endif /* MDL_START */
static void mdlOutputs(SimStruct *S, int_T tid) {
array_ptr = mexGetVariable("global", "testVar");
/* Increment both MATLAB and MEX counters by 1 */
mxGetPr(array_ptr)[0]+=1;
/* Put variable in MATLAB global workspace */
mexPutVariable("base", "testVar", array_ptr);
//ssPrintf("mdlOutputs\n");
}
static void mdlTerminate(SimStruct *S){
ssPrintf("mdlTerminate\n");
mxDestroyArray(array_ptr);
}
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
Did I miss anything?
If I add the code in mdlOutputs
if (array_ptr == NULL ) {
array_ptr=mxCreateDoubleMatrix(1,1,mxREAL);
}
just after
array_ptr = mexGetVariable("global", "testVar");
the simulink model runs properly.
  1 个评论
JanSc
JanSc 2017-2-14
Hi,
I observed a similar behavior.
Took me an hour to realize, that all my code in mdlStart() is actually properly executed just the debugging output from ssPrintf() is not displayed.
BR, Jan

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Embedded Coder 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by