Matlab S-function segmentation violation

2 ビュー (過去 30 日間)
ander
ander 2015 年 3 月 27 日
回答済み: ander 2015 年 3 月 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);
}
}

回答 (2 件)

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

ander
ander 2015 年 3 月 30 日
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.

カテゴリ

Help Center および File ExchangePrepare Model Inputs and Outputs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by