Matlab S-function segmentation violation

2 visualizaciones (últimos 30 días)
ander
ander el 27 de Mzo. de 2015
Respondida: ander el 30 de Mzo. de 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);
}
}

Respuestas (2)

Anusha B
Anusha B el 30 de Mzo. de 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 el 30 de Mzo. de 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.

Categorías

Más información sobre Prepare Model Inputs and Outputs en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by