Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting a Simulink block's number of output ports depending on its inport datatypes in a level 2 C-mex S-Function
    primarykey
    data
    text
    <p>I'm trying to create a level 2 S-Function written in C that has <em>different numbers of output ports</em> depending on the <em>signals' datatypes</em> that are connected to the inports.</p> <p>The practical background is that I have some other S-Functions that define custom datatypes by calling <code>ssRegisterDataType</code>. These datatypes describe pointers to certain data. </p> <p>I now want to have another S-Function that can consume these custom datatypes (pointers) and, depending on what pointer type is fed into them, output certain data. </p> <p>I tried setting the number of output ports through <code>ssSetNumOutputPorts</code> by</p> <pre><code>static void mdlSetInputPortDataType(SimStruct *S, int portIndex,DTypeId dType) { if( portIndex == 0 ) { if( dType == ssGetDataTypeId(S, "ptrtype1" ) ) { if (!ssSetNumOutputPorts(S, nOutportsPtr1)) return; } else if( dType == ssGetDataTypeId(S, "ptrtype2" ) ) { if (!ssSetNumOutputPorts(S, nOutportsPtr2)) return; } else if( dType == ssGetDataTypeId(S, "ptrtype3" ) ) { if (!ssSetNumOutputPorts(S, nOutportsPtr3)) return; } else if( dType == ssGetDataTypeId(S, "ptrtype4" ) ) { if (!ssSetNumOutputPorts(S, nOutportsPtr4)) return; } else { ssSetErrorStatus(S, "Input data type is not supported."); return; } if (!ssSetInputPortDataType(S, portIndex, dType)) return; } } /* mdlSetInputPortDataType */ </code></pre> <p>while in <code>mdlInitializeSizes</code> I set the inport's data type to be <code>DYNAMICALLY_TYPED</code>.</p> <p>But Simulink keeps telling me I should set the inport data type in <code>mdlSetInputPortDataType</code> on a call to <code>ssSetNumOutputPorts</code>. I assume inside this function only the data type of inports may be changed.</p> <p>Does anybody know of a solution to this problem? The only workaround I can think of is masking the S-Function and having the user to manually select the pointer type that he wishes to be processed. With data type propagation this seems messy and unnecessary though.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload