필터 지우기
필터 지우기

mdlStart is not called during the execution of s-function

조회 수: 9 (최근 30일)
Janez Podobnik
Janez Podobnik 2015년 7월 7일
댓글: JanSc 2017년 2월 14일
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