I cannot run this file-io-c-s-function?

If i run this model, i got the following error, ==> mex at 222 Unalble to complete successfully
Can anyone help me for the reason...

댓글 수: 9

How did you run the "mex" command?
Ravi
Ravi 2013년 6월 25일
편집: Walter Roberson 2013년 6월 25일
just i created a model..
/* Give S-function a name */
#define S_FUNCTION_NAME cfileiosfun
#define S_FUNCTION_LEVEL 2
/* Include SimStruct definition and file I/O functions */
#include "simstruc.h"
#include <stdio.h>
/* Called at the beginning of the simulation */
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 0);
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
return;
}
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 0)) return;
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 1);
ssSetOutputPortDataType(S,0,SS_SINGLE);
ssSetNumPWork(S,1);
ssSetNumSampleTimes(S, 1);
}
/* Set sample times for the block */
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, 1.0);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_START /* Change to #undef to remove function */
#if defined(MDL_START)
/* Function: mdlStart =======================================================
* Abstract:
* This function is called once at start of model execution. If you
* have states that should be initialized once, this is the place
* to do it.
*/
static void mdlStart(SimStruct *S)
{
/*at start of model execution, open the file and store the pointer
*in the pwork vector */
void** pwork = ssGetPWork(S);
FILE *datafile;
datafile = fopen("datafile.dat","r");
pwork[0] = datafile;
}
#endif /* MDL_START */
/* Function: mdlOutputs =======================================================
* Abstract:
* In this function, you compute the outputs of your S-function
* block. Generally outputs are placed in the output vector, ssGetY(S).
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
//get pointer to the block's output signal
real_T *y = ssGetOutputPortSignal(S,0);
/*get pointer to array of pointers, where the first element is the address
*of the open file */
void** pwork = ssGetPWork(S);
/*read a floating point number and then the comma delimiter
*store the result in y*/
fscanf(pwork[0],"%f%*c",y);
}
/* Function: mdlTerminate =====================================================
* Abstract:
* In this function, you should perform any actions that are necessary
* at the termination of a simulation. For example, if memory was
* allocated in mdlStart, this is the place to free it.
*/
static void mdlTerminate(SimStruct *S)
{
//close the file
void** pwork = ssGetPWork(S);
FILE *datafile;
datafile = pwork[0];
fclose(datafile);
}
/*=============================*
* Required S-function trailer *
*=============================*/
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
this is the code... this code i have written in s-finction... but the thing is i have given the name iosfun to that s-function but it is showing the above error that iosfun doesn't exist
You did not show us the log of the error; you just showed that it said the mex did not complete.
Did you use
mex -setup
to choose a compiler? Which compiler did you choose, which OS are you on, which MATLAB version are you using, and are you using 32 or 64 bit MATLAB?
Ravi
Ravi 2013년 6월 25일
Walter Roberson : i tried with Lcc-win32, My OS: Windows Xp, MATLAB 7.10.0 (R2010a)(32-bit)
after mex -setup >> mex cfileiosfun.c
then i am getting following error D:programfiles\MATLAB\R2010a\bin\mex.pl: Error: 'cfileiosfun.c' not found
Error using ==> mex at 222 unable to complete successfully
then what to do... Can u explain
Thanks in advance Ravi Kiran
Is the file cfileiosfun.c in your current working directory in MATLAB?
Ravi
Ravi 2013년 6월 26일
yes it is in currennt directory
Ravi
Ravi 2013년 6월 26일
thank you Kaustubha Govind & Walter Roberson with your comments & my implemenntation it finally worked.. this is my first attempt using s-functions.. Thanks 4 ur support... hav a nice dayy....
Ravi
Ravi 2013년 6월 27일
The model is working well for a textfile with 100 values in it.. But for my project since it is real time, my text file will contain around 70000 values.. So when i am running the model with >1000 or something... MATLAB is Closing reporting that it is not responding.... So what to do now... Can u explain..
Ravi: Please set breakpoints in your code and narrow down the issue to a line of code where it always crashes. You are not providing enough information for us to be able to help.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

질문:

2013년 6월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by