Matlab S-function segmentation violation
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Anusha B
2015-3-30
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Prepare Model Inputs and Outputs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!