How to initialize Pwork in TLC file?

6 views (last 30 days)
Neha
Neha on 27 Jul 2017

I am trying to use pwork vector as a way to store a pointer to a dll that I am loading. However, I also have a tlc file which I need to ( I think) incorporate this pwork vector somehow. I couldn't find much documentation for how to use pwork in tlc code, and would really appreciate if someone could help out. I've tried what I have below and it doesn't compile.

Here is the tlc code excerpt (the Pword stuff is probably wrong):

%%Function: Start ========================================================
%function Start(block, system) Output
    /* S-Function "WritetoVibrotactor_wrapper" Block: %<Name> */
    %assign pxd = LibBlockDWorkAddr(DSTATE, "", "", 0)
    %assign pwd = LibBlockPWork(PWORK, "", "", 0)
    WritetoVibrotactor_Start_wrapper(%<pxd>,%<pwd>);
    %%
  %endfunction

This is my s function code:

#define MDL_START
void mdlStart(SimStruct *S){
    real_T *xD = ssGetDiscStates(S);
    void *dllptr = LoadLibrary("TactorInterface.dll");
    ssSetPWorkValue(S,0,dllptr);
    WritetoVibrotactor_Start_wrapper(xD,dllptr);
}

Here is the wrapper code:

void WritetoVibrotactor_Start_wrapper(real_T *xD, void *hGetProcIDDLL)
{
 // void * hGetProcIDDLL = LoadLibrary("TactorInterface.dll");
 InitializeFn _InitializeTI = (InitializeFn)GetProcAddress(hGetProcIDDLL,"InitializeTI");
 ConnectFn _Connect = (ConnectFn)GetProcAddress(hGetProcIDDLL, "Connect");
 DiscoverFn _Discover = (DiscoverFn)GetProcAddress(hGetProcIDDLL, "Discover");
 ChangeGainFn _ChangeGain = (ChangeGainFn)GetProcAddress(hGetProcIDDLL, "ChangeGain");
 ChangeFreqFn _ChangeFreq = (ChangeFreqFn)GetProcAddress(hGetProcIDDLL, "ChangeFreq");
 PulseFn _Pulse = (PulseFn)GetProcAddress(hGetProcIDDLL, "Pulse");
 GetDiscoveredDeviceNameFn _GetDiscoveredDeviceName = (GetDiscoveredDeviceNameFn)GetProcAddress(hGetProcIDDLL, "GetDiscoveredDeviceName");
 CloseFn _Close = (CloseFn)GetProcAddress(hGetProcIDDLL, "Close");
 ShutdownFn _ShutdownTI = (ShutdownFn)GetProcAddress(hGetProcIDDLL, "ShutdownTI");
       int initret = _InitializeTI();
       int numdev = _Discover(3);
      const char *dev = _GetDiscoveredDeviceName(0);
      void *ptr = NULL;
     xD[1] = _Connect(dev,1,ptr);
       _ChangeFreq(0,1,1500,0);
       _ChangeGain(0,1,100,0);
       _Pulse(0,1,1000,0);
       FreeLibrary(hGetProcIDDLL);
  }

Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!