using ssSetNumInputPorts but no change in inputports...
이전 댓글 표시
I am trying to set the number of input ports of my s-function block (written in C-code). It seems to be easy but apparently I am overlooking something because after compiling my code, the s-function block still only has one input port (instead of the 7 defined). What am I missing? Below the code that I defined in mdlInitializeSizes
int_T nInputPorts = 7; /* number of input ports */
int_T index;
if (!ssSetNumInputPorts(S,nInputPorts)) return;
if(!ssSetInputPortVectorDimension(S, 0, 6)) return;
if(!ssSetInputPortVectorDimension(S, 1, 1)) return;
if(!ssSetInputPortVectorDimension(S, 2, 2)) return;
if(!ssSetInputPortVectorDimension(S, 3, 1)) return;
if(!ssSetInputPortVectorDimension(S, 4, 1)) return;
if(!ssSetInputPortVectorDimension(S, 5, 1)) return;
if(!ssSetInputPortVectorDimension(S, 6, 1)) return;
for (index = 0; index < 7; index++) {
ssSetInputPortDirectFeedThrough(S, index, 1);
ssSetInputPortComplexSignal(S, index, COMPLEX_NO);
}
ssSetNumSampleTimes( S, 1);
ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
댓글 수: 2
Ingrid
2012년 12월 5일
mohammed Hanneef
2018년 11월 22일
I faced the same 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.
답변 (3개)
You need to command
MEX thenameofyourCcode
In MATLAB's command window, and then reopen the model to see the change.
Guy Rouleau
2012년 12월 6일
0 개 추천
Your code looks good... I can't identify what is going wrong.
This is probably not the problem, but make sure MATLAB sees the correct s-function by executing "which -all nameOfYourFunction".
Also ensure mex really builds your last version by doing "clear mex" and deleting the existing mex-file.
If this is not the problem, try attaching a debugger and stepping line by line to better understand what is going on:
Note: Even if the ports do not exist, ssGetInputPortRealSignalPtrs will not give errors... it will just read wrong address in memory. You can enable the "Array Out of Bounds" diagnostic to see if this happens. Enable this diagnostic only for diagnostic, it is very expensive on performance.
댓글 수: 3
Ingrid
2012년 12월 7일
Ingrid
2012년 12월 14일
Guy Rouleau
2012년 12월 14일
Please try to simplify your code as much as possible and contact technical support. There is something strange here and without looking at your files this is very difficult to figure it out.
mohammed Hanneef
2018년 11월 22일
0 개 추천
I face the same 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.
카테고리
도움말 센터 및 File Exchange에서 Configure C/C++ S-Function Features에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!