mex file compiling error
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I want to create mex file but the compiler give this error..
1. Error ForceSensor.c: 121 undeclared identifier `USE_DEFAULT_SIM_STATE' 2. Warning ForceSensor.c: 121 possible usage of USE_DEFAULT_SIM_STATE before definition 1 errors, 1 warnings
anybody could help
채택된 답변
Kaustubha Govind
2012년 2월 13일
0 개 추천
Is this an S-function? If yes, you are probably missing:
#include "simstruc.h"
댓글 수: 3
Ken Atwell
2012년 2월 13일
See also http://www.mathworks.com/matlabcentral/answers/1850-mex-error-undeclared-identifier-what-does-this-mean
Ahmad Faizal
2012년 2월 14일
Yes, it is an S-Function..I'm using basic C-mex template from Matlab 2006a which already included the "simstruc.h". The program are as follow.
#define S_FUNCTION_NAME ForceSensor
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"
#include "windows.h"
int CJr3_ReadJr3(int, int *, int);
int CJr3_WriteJr3(int addr, int *data, int nump);
void CJr3_RegisterWinDriver(void);
int CJr3_DeInitJr3(void);
int CJr3_InitJr3(unsigned long VendorID, unsigned long DeviceID, int nump);
int CJr3_MemAllocate(DWORD addr, int i);
int CJr3_download(DWORD BaseAddressHH, DWORD BaseAddressLL);
void CJr3_Wait(void);
int CJr3_GetFx(int, int); // Output raw Fx, input filter # and DSP #
int CJr3_GetFy(int, int); // Output raw Fy, input filter # and DSP #
int CJr3_GetFz(int, int); // Output raw Fz, input filter # and DSP #
int CJr3_GetMx(int, int); // Output raw Mx, input filter # and DSP #
int CJr3_GetMy(int, int); // Output raw My, input filter # and DSP #
int CJr3_GetMz(int, int); // Output raw Mz, input filter # and DSP #
void CJr3_ResetOffset(int); // Input DSP #
/* Error handling
* --------------
*
* You should use the following technique to report errors encountered within
* an S-function:
*
* ssSetErrorStatus(S,"Error encountered due to ...");
* return;
*
* Note that the 2nd argument to ssSetErrorStatus must be persistent memory.
* It cannot be a local variable. For example the following will cause
* unpredictable errors:
*
* mdlOutputs()
* {
* char msg[256]; {ILLEGAL: to fix use "static char msg[256];"}
* sprintf(msg,"Error due to %s", string);
* ssSetErrorStatus(S,msg);
* return;
* }
*
* See matlabroot/simulink/src/sfuntmpl_doc.c for more details.
*/
/*====================*
* S-function methods *
*====================*/
/* Function: mdlInitializeSizes ===============================================
* Abstract:
* The sizes information is used by Simulink to determine the S-function
* block's characteristics (number of inputs, outputs, states, etc.).
*/
static void mdlInitializeSizes(SimStruct *S)
{
/* See sfuntmpl_doc.c for more details on the macros below */
ssSetNumSFcnParams(S, 0); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */
return;
}
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 0)) return;
//ssSetInputPortWidth(S, 0, 1);
//ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
/*
* Set direct feedthrough flag (1=yes, 0=no).
* A port has direct feedthrough if the input is used in either
* the mdlOutputs or mdlGetTimeOfNextVarHit functions.
* See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
*/
//ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 2)) return;
ssSetOutputPortWidth(S, 0, 6);
ssSetOutputPortWidth(S, 1, 6);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
/* Specify the sim state compliance to be same as a built-in block */
ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
ssSetOptions(S, 0);
/* Initialize force sensor board */
CJr3_RegisterWinDriver();
{
int flag,data;
flag = CJr3_InitJr3(0x1762, 0x3112, 2);
if(flag==0)
printf("Succeeded in Force Sensor Board\n");
else
printf("Error in Force Sensor Board\n");
CJr3_ReadJr3(0xfc, &data, 2);
printf("unit:%d\n",data);
}
}
/* Function: mdlInitializeSampleTimes =========================================
* Abstract:
* This function is used to specify the sample time(s) for your
* S-function. You must register the same number of sample times as
* specified in ssSetNumSampleTimes.
*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function */
#if defined(MDL_INITIALIZE_CONDITIONS)
/* Function: mdlInitializeConditions ========================================
* Abstract:
* In this function, you should initialize the continuous and discrete
* states for your S-function block. The initial states are placed
* in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S).
* You can also perform any other initialization activities that your
* S-function may require. Note, this routine will be called at the
* start of simulation and if it is present in an enabled subsystem
* configured to reset states, it will be call when the enabled subsystem
* restarts execution to reset the states.
*/
static void mdlInitializeConditions(SimStruct *S)
{
}
#endif /* MDL_INITIALIZE_CONDITIONS */
#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)
{
}
#endif /* MDL_START */
/* Function: mdlOutputs =======================================================
* Abstract:
* In this function, you compute the outputs of your S-function
* block.
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
int i,addr,data,fullscale,filter;
// const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);
real_T *y1 = (real_T *)ssGetOutputPortSignal(S,0);
real_T *y2 = (real_T *)ssGetOutputPortSignal(S,1);
filter=0;
for(i=0;i<6;i++){
addr = 0x90+ i + filter * 8;
CJr3_ReadJr3(addr, &data, 1);
if(data&0x8000)
data |= 0xffff0000;
addr = 0x80+ i;
CJr3_ReadJr3(addr, &fullscale, 1);
if(i<3)
y1[i] = (real_T)data /16384.0*fullscale;
else
y1[i] = (real_T)data /16384.0*fullscale/10;
}
for(i=0;i<6;i++){
addr = 0x90+ i + filter * 8;
CJr3_ReadJr3(addr, &data, 2);
if(data&0x8000)
data |= 0xffff0000;
addr = 0x80+ i;
CJr3_ReadJr3(addr, &fullscale, 2);
if(i<3)
y2[i] = (real_T)data /16384.0*fullscale;
else
y2[i] = (real_T)data /16384.0*fullscale/10;
}
}
#define MDL_UPDATE /* Change to #undef to remove function */
#if defined(MDL_UPDATE)
/* Function: mdlUpdate ======================================================
* Abstract:
* This function is called once for every major integration time step.
* Discrete states are typically updated here, but this function is useful
* for performing any tasks that should only take place once per
* integration step.
*/
static void mdlUpdate(SimStruct *S, int_T tid)
{
}
#endif /* MDL_UPDATE */
#define MDL_DERIVATIVES /* Change to #undef to remove function */
#if defined(MDL_DERIVATIVES)
/* Function: mdlDerivatives =================================================
* Abstract:
* In this function, you compute the S-function block's derivatives.
* The derivatives are placed in the derivative vector, ssGetdX(S).
*/
static void mdlDerivatives(SimStruct *S)
{
}
#endif /* MDL_DERIVATIVES */
/* 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)
{
CJr3_DeInitJr3();
}
/*======================================================*
* See sfuntmpl_doc.c for the optional S-function methods *
*======================================================*/
/*=============================*
* 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
Kaustubha Govind
2012년 2월 14일
Did you verify if the link that Ken posted applies to your version of MATLAB? The error could be due to a bug.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Create C/C++ S-Functions에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
