User`s guide
Implementing Device Drivers
10-13
Next define a variable used to store the integer (which is the number of
channels in this example):
uint_T num_channels;
Finally, extract the value from the argument (which is of type mxArray *), and
assign it to a type u
int_T (unsigned integer). Since the parameter is a single
integer, you need only the first element in the parameter:
num_channels = mxGetPr(THIRD_ARGUMENT)[0];
The macro ssGetSFcnParam is part of the S-function API. It is defined in
simstruc.h anddescribedintheUsing Simulink manual.
The function
mxGetPr is part of the External Interface Library. Its function
prototype is in
mex.h and rt_matrx.h. It is described in the Application
Program Interface Guide.
Initializing Sizes — Input Devices
The mdlInitializeSizes function sets size information in the SimStruct.For
example, the following definition of
mdlInitializeSizes initializes a typical
ADC (analog to digital converter) board:
static void mdlInitializeSizes(SimStruct ∗S)
{
uint_T num_channels = mxGetPr(THIRD_ARGUMENT)[0];
ssSetNumSFcnParams(S, 3); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual param’s */
return;
}
ssSetNumInputPorts(S, 0);
ssSetNumOutputPorts(S, num_channels);
ssSetNumSampleTimes(S, 1);
{
uint_T i;
for(i=0; i<num_channels;i++){
ssSetInputPortdirectfeedthrough(S,i,0);
}
}
}