-1

#define S_FUNCTION_NAME myfunction_sFun

#define S_FUNCTION_LEVEL 2

#define MDL_INITIAL_SIZES

#define MDL_INITIALIZE_SAMPLE_TIMES

#include "tmwtypes.h"

#include "simstruc_types.h"

#include "mex.h"

#include "simstruc.h"

void mdlInitializeSizes(SimStruct *S)

{

ssPrintf("Initialize\n");

  //My code has been removed from here

ssPrintf("End Initialize\n");

}

void mdlInitializeSampleTimes(SimStruct *S)

{

ssPrintf("Sample Times\n");

}

#define MDL_OUTPUTS

#ifdef MDL_OUTPUTS

void mdlOutputs(SimStruct *S, int_T tid)

{

ssPrintf("Outputs\n");

}

#endif

#define MDL_START

#ifdef MDL_START

void mdlStart(SimStruct *S)

{

ssPrintf("Start\n");

}

#endif

void mdlTerminate(SimStruct *S){}

/=============================

  • Required S-function trailer *

    =============================/

#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

Or. D
  • 1
  • 1
  • When I run my s-function (either in MATLAB or via simulink diagram), I only see the "Initialize" and "End Initialize" outputs. The s-function never executes the other mdl* functions. Does anyone know why this could be? I've also verified this by attaching the MATLAB process to Visual Studio and debugging - breakpoints in every function except mdlInitializeSizes are not reached. – Or. D Feb 28 '17 at 22:21
  • Your question has problems with the code formatting. Also your comment should be part of the question itself. – MartinTeeVarga Mar 01 '17 at 00:41
  • Do you try to compile your code? In this case, sometimes you should have a look at the tlc-file (if it exists in your case). There might be some functions left out there, and therefore they will not get called. – Lemonbonbon Nov 07 '18 at 14:00

1 Answers1

1

mdlStart and mdlOutputs are option methods that only get called in certain circumstances. For instance, mdlOutputs only gets called if there are any outputs defined - which in your case there aren't. (I am a little surprised that mdlStart is not being called.)

See the documentation Simulink Engine Interaction with C S-Functions for which methods are optional, and their calling sequence.

Phil Goddard
  • 10,571
  • 1
  • 16
  • 28
  • Thanks for the reply Phil. I removed some of the code I have in order to post but my mdlInitializeSizes() defines outputs for my s-function (I believe this is what you're talking about). I will look at the documentation and see if I find anything that stands out - will loop back here when/if I resolve this issue. – Or. D Mar 01 '17 at 16:27