我正在尝试在自定义S函数中使用PWork向量。我希望使用它们存储指向我需要使用的DLL的指针。
在我的mdlInitializeSizes中我有:
ssSetNumPWOrk(S,1);
在mdlRTW我有:
static void mdlRTW(SimStruct *S)
{
if(!ssWrteRTWWorkVect(S, "PWork",1,"PworkDLL",1)) {
return; /*An error will be reported by SL*/
}
}
在mdlStart中:
#define MDL_START
void mdlStart(SimStruct *S){
real_T *xD = ssGetDiscStates(S);
HINSTANCE dllptr = LoadLibrary("TactorInterface.dll");
void **Pwork = ssGetPWork(S);
Pwork[0] = dllptr;
//ssSetPWorkValue(S,0,dllptr);
WritetoVibrotactor_Start_wrapper(xD,Pwork);
}
我还需要在.tlc文件中实现此PWork,但我不知道如何正确执行此操作。似乎没有太多关于如何正确执行此操作的文档或示例。到目前为止,我确实在.tlc文件中有这个:
%%Function: Start ========================================================
%function Start(block, system) Output
/* S-Function "WritetoVibrotactor_wrapper" Block: %<Name> */
%assign pxd = LibBlockDWorkAddr(DSTATE, "", "", 0)
%assign pwd = LibBlockPWork(PworkDLL, "", "", 0)
WritetoVibrotactor_Start_wrapper(%<pxd>,%<pwd>);
%%
%endfunction
在我的包装函数中:
void WritetoVibrotactor_Start_wrapper(real_T *xD, void *Pwork)
{
HINSTANCE hGetProcIDDLL;
hGetProcIDDLL = (HINSTANCE)Pwork[0];
// void * hGetProcIDDLL = LoadLibrary("TactorInterface.dll");
InitializeFn _InitializeTI =
(InitializeFn)GetProcAddress(hGetProcIDDLL,"InitializeTI");
//other stuff...
}
如果我尝试构建模型,我会在.tlc文件中获得一个未定义的标识符PworkDLL。