Level 2 C++ S-function not showing multiple input output ports

조회 수: 7 (최근 30일)
adam honse
adam honse 2017년 11월 21일
답변: mohammed Hanneef 2018년 11월 22일
Hello, I have a C++ Level 2 Sfunction that is compiling via Mex but when i bring it into simulink, it shows only one input port, and one output port. Not sure what i need to do here. Am i missing something?
#ifdef __cplusplus
extern "C" { // use the C fcn-call standard for all functions
#endif // defined within this scope
#define S_FUNCTION_LEVEL 2
...
#define NParam 207 // Total number of paramters
#define NInputs 205 // Number of input ports
#define NOutputs 52 // Total Number of output ports
... (some omitted #defines)
#include "simstruc.h"
... (some omitted #includes)
static void mdlInitializeSizes(SimStruct *S)
{
/* Number of expected parameters */
ssSetNumSFcnParams(S, NParam);
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */
return;
}
/* Setup for input ports */
if (!ssSetNumInputPorts(S, NInputs)) return;
for (int i=0; i<NInputs; i++){ /* loop stuff ommited /*}
/* Setup for output ports */
if (!ssSetNumOutputPorts(S, NOutputs)) return;
for (int j=0; j<NOutputs; j++){ /* loop stuff ommited /*}
/* No continuous and discrete states */
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
ssSetNumSampleTimes(S, NSampleTimes);
ssSetNumRWork(S, NUMRWORK);
ssSetNumIWork(S, NUMIWORK);
ssSetNumPWork(S, NUMPWORK);
ssSetNumModes(S, NUMMODES);
ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S, 0);
}
... (some other functions)
  댓글 수: 1
adam honse
adam honse 2017년 11월 22일
An update, i deleted the simulink block and re-added the s-func, and now everytime i click ok or apply, after specifying the s-func, matlab totally crashes (*poof*).

댓글을 달려면 로그인하십시오.

채택된 답변

Mark McBroom
Mark McBroom 2017년 11월 27일
code looks OK. In your Simulink S-Function block, did you create a mask with 207 parameters and pass all 207 parameters in the "S-function parameters:" field?
  댓글 수: 1
adam honse
adam honse 2017년 11월 27일
It finally updated after i added a missing file for a dll i was including in the s-func. It looks like it was killing the whole thing when it couldn't load the dll.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

mohammed Hanneef
mohammed Hanneef 2018년 11월 22일
I had similar problem but then realized one of the reason for this is the Sfunction file name provided in the S-function Name shall be written without an extension such as "mysfunction.c shall be written as mysfunction". when i did this it worked for me.
check it out

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by