I am trying to use PWork vectors in a custom S-Function. I am hoping to use them to store a pointer to a DLL that I need to use.
In my mdlInitializeSizes I have:
ssSetNumPWOrk(S,1);
In mdlRTW I have:
static void mdlRTW(SimStruct *S)
{
if(!ssWrteRTWWorkVect(S, "PWork",1,"PworkDLL",1)) {
return; /*An error will be reported by SL*/
}
}
In 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);
}
I need to also implement this PWork in the .tlc file but I have no idea how to do this correctly. There doesn't seem to be much documentation or examples for how to do this correctly. I do have this so far in the .tlc file:
%%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
In my wrapper function:
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...
}
If I try to build the model I get an undefined identifier PworkDLL in the .tlc file.