How to initialize Pwork in TLC file?
조회 수: 6 (최근 30일)
이전 댓글 표시
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>);
%%
%endfunctionThis 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);
}
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!