static void mdlStart(SimStruct *S)
{
if (mxGetScalar(ssGetSFcnParam(S, SS_PARAMETER_BLOCK_TYPE)) == SS_BLOCKTYPE_CONFIG)
{
mxArray *work_vector = NULL; // mxCalloc(1, sizeof(mxArray*));
work_vector = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
mexMakeArrayPersistent(work_vector);
if(work_vector == NULL)
{ ssSetErrorStatus(S, "Faild to alloc memory for pWork Vector.\n"); }
else
{
ssSetPWorkValue(S, SS_PWORK_CONF_TIC, work_vector);
if(S->work.pWork[0] != work_vector)
{ ssSetErrorStatus(S, "[CONFBLOCK] Failed to assign PWork vector.\n"); }
// Init 'tic' value
mexCallMATLAB(1, &work_vector, 0, NULL, "tic");
}
}
}
static void mdlUpdate(SimStruct *S, int_T tid)
{
if (mxGetScalar(ssGetSFcnParam(S, SS_PARAMETER_BLOCK_TYPE)) == SS_BLOCKTYPE_CONFIG)
{
// Block Information
mxArray *tic, *elapsed;
tic = (mxArray*) ssGetPWork(S);
// tic = (mxArray*) ssGetPWorkValue(S, , SS_PWORK_CONF_TIC);
elapsed = mxCreateDoubleMatrix(1,1, mxREAL);
mexCallMATLAB(1, &elapsed, 1, &tic, "toc");
// Evaluate 'toc' result
double *secs = mxGetDoubles(elapsed);
DEBUG_MSG("[ConfigBlock] TSM_Timer_Milliseconds (%u)", milliseconds);
// Call tsm_timer
tsm_timer_milliseconds(milliseconds);
// Update _tic
mexCallMATLAB(1, &tic, 0, NULL, "tic");
}
}
2 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/425428-how-to-reference-mxarray-between-sfunctions-with-help-of-pwork#comment_626222
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/425428-how-to-reference-mxarray-between-sfunctions-with-help-of-pwork#comment_626222
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/425428-how-to-reference-mxarray-between-sfunctions-with-help-of-pwork#comment_626538
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/425428-how-to-reference-mxarray-between-sfunctions-with-help-of-pwork#comment_626538
Sign in to comment.