Matlab S-function segmentation violation
2 views (last 30 days)
Show older comments
Hi everybody! I am running a simulation and matlab gives me this error after 30 minutes:
For me it is very rare because I am not using any input at the S-function. I only use outputs so I dont understand what is happening. I am attaching the function where i initialized everything.
static void mdlInitializeSizes(SimStruct *S)
{
// hay 1 parametro que se introduce por simulink
ssSetNumSFcnParams(S, 1);
// si no estan los parametros esperados salta el error
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S))
{
return;
}
//Se asignan las entradas de matlab a las variables
periodo = 1*(double) mxGetPr (ssGetSFcnParam(S,0))[0]; /* parameter[1]: Sampling period */
/* OUTPUTS */
//especifica las SALIDAS
if (!ssSetNumOutputPorts(S, max_vars)) return;
//Se especifica el ancho y tipo de las variables que en este caso todas son de 1 para simplificar
for (i=0;i<max_vars;i++)
{
ssSetOutputPortWidth(S, i, 1);
ssSetOutputPortDataType( S, i, SS_BOOLEAN );
}
ssSetNumSampleTimes(S, 1);
ssSetOptions(S, 0);
//VARDB
//se conecta a la vardb
bool opened = do1_vardb.ConnectVarDB("DO1");
//se comprueba que se ha conectado a la vardb que se quiera
const char *name = do1_vardb.GetVarDBName();
//se conectan todas las variables
for(i = 1; i < 10; ++i){
sprintf(buffer, "%s%d","DO_VALUE_CHN_0", i);
CVarDBAccess *varaccess = do1_vardb.ConnectVar(buffer, Boolean1, 1);
accesses.push_back(varaccess);
}
for(i = 10; i <= max_vars; ++i){
sprintf(buffer, "%s%d","DO_VALUE_CHN_", i);
CVarDBAccess *varaccess = do1_vardb.ConnectVar(buffer, Boolean1, 1);
accesses.push_back(varaccess);
}
}
0 Comments
Answers (2)
Anusha B
on 30 Mar 2015
Hi Ander,
You can debug your S-function either in Simulink or using a third-party software. The following link can help you in this regard:
0 Comments
See Also
Categories
Find more on Prepare Model Inputs and Outputs in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!