Matlab S-function segmentation violation

2 views (last 30 days)
ander
ander on 27 Mar 2015
Answered: ander on 30 Mar 2015
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);
}
}

Answers (2)

Anusha B
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:

ander
ander on 30 Mar 2015
I know that. But the problem is that the simulation runs more or less 30 minutes and suddenly goes to crash. I don´t know how to solve the problem because is not something that happens at the beginning of the simulation. The crash happens after 30 minutes.

Categories

Find more on Prepare Model Inputs and Outputs in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!