Modify the MaskDIsplay of a block by using c sfunction
Show older comments
Hello everyone,
I'm wondering if it's possible to modify the MaskDisplay of a block by using a C sfunction. I know I can get the MaskDisplay parameter as string by using this Matlab instruction
get_param(gcb,'MaskDisplay')
but for my purpose ( ... and for the advisor of my internship -_-" ) I can't directly use it, because I have to stuck with C-Sfunction. so I'm here asking if if there is a C instruction to do that
thanks 4 reading any suggestion will be appreciate
have a good day
1 Comment
grapevine
on 11 May 2012
Accepted Answer
More Answers (2)
Bruce Jackson
on 4 Sep 2012
Edited: Bruce Jackson
on 4 Sep 2012
0 votes
I have a similar question in that I would like to label the S-function mask based on the data from an external file I'm loading at mdlInitializeSizes. Is is possible to edit the mask from within a C++ Sfunction? Seems like there should be some way for Matlab/Simulink and an S-function to be able to communicate/interrogate each other beyond the specified S-function calls, for more flexibility.
However, (for instance), I can't seem to even use ssPrintf() inside of mdlProcessParameters or mdlCheckParameters; ssPrintf() works fine in mdlInitializeSizes, but using mexCallMATLAB() within mdlInitializeSizes doesn't appear to work.
3 Comments
Kaustubha Govind
on 4 Sep 2012
Bruce: It is possible that the output of ssPrintf is getting suppressed in mdlProcessParameters or mdlCheckParameters, but I can't tell for sure. Could you explain how your call to mexCallMATLAB is failing exactly? I would recommend trying to step through your S-function to understand the failure better. Please see Debugging C MEX S-Functions.
Bruce Jackson
on 5 Sep 2012
Edited: Bruce Jackson
on 5 Sep 2012
void test(SimStruct *S) {
mxArray *lhs;
const char *cmd = "get_param(gcb,'name')";
mexCallMATLAB(1, &lhs, 0, NULL, cmd);
char msg[256];
if(lhs) {
int m = (int) mxGetM(lhs);
int n = (int) mxGetN(lhs);
sprintf(msg, "lhs = (%d x %d)\n", m, n);
ssPrintf(msg):
} else {
ssPrintf("lhs was null.\n");
}
}
If I call test(S) from mdlInitializeSizes() I get strange results: if cmd is set to get_param(gcb,'name') as shown, Matlab crashes. If I define cmd = "who" then I don't get the anticipated result (the contents of the workspace): returned lhs is a 2x1 cell array containing two strings, "MaskParam_L_1" and "filepath" (filepath is the sole parameter for this Sfunction) when I update the diagram (<ctrl>-d).
If I move the call to test() to either mdlCheckParameters() or mdlProcessParameters() nothing is printed in the command window, even after changing the parameter, updated the diagram, or running the model. Even a raw ssPrintf("hello\n") fails to print from inside either routine.
Note that I am not invoking mdlCheckParameters or mdlProcessParameters explicitly but I gather they are supposed to be called when I change a model parameter; but I can't see that they are being called even then.
Kaustubha Govind
on 6 Sep 2012
Edited: Kaustubha Govind
on 6 Sep 2012
The result of "who" is expected - essentially, your commands are running in the mask workspace of the S-function, which is why you are seeing mask parameters (MaskParam_L_1 could be internal data). Note that gcb could be empty (it returns the currently selected block in the model, not the currently executing block). mexCallMATLAB is a bad choice when errors may occur because I believe it terminates the MEX-function, you may want to use mexCallMATLABWithTrap to capture error information. It is safer to use the output of ssGetPath in place of gcb. Regarding mdlCheckParameters and mdlProcessParameters - after consulting the documentation, it seems like these functions are optionally called. Could you try setting a breakpoint instead of using ssPrintf (since stdout could be suppressed)?
Bruce Jackson
on 7 Sep 2012
0 votes
I can confirm that mdlCheckParams and mdlProcessParams are not being called, despite me changing the value of the single block parameter in the Simulink editor (in this case, the path to the file I want the SFunction to load data from) by using the debugger.
What I'm attempting to do is load an ANSI/AIAA S-119 model (see http://daveml.org ) into a Simulink Sfunction. That XML-based format provides nonlinear mappings between scalar inputs and outputs, so in addition to needing to change the number of input and output ports on initialization (the SFunction mdlInitializeSizes works very nicely to perform this function), I would like to be able to label the ports, too, and I fail to see a direct way to do this unless your suggestion of using ssGetPath (thanks!) lets me use the mexCallMatlabWithTrap method to issue mask drawing commands to my own block.
This indirect workaround seems cumbersome and unnecessary; I expected to find some introspection capability to allow a C/C++ SFunction be able to manipulate the appearance of the Simulink block that contains it.
Thanks very much for your support,
-- Bruce
1 Comment
Kaustubha Govind
on 7 Sep 2012
Bruce: At the risk of sounding trivial - have you place the statement "#define MDL_CHECK_PARAMETERS" above mdlCheckParameters and "#define MDL_PROCESS_PARAMETERS" above mdlProcessParameters?
Also, I'm confused about what your ideal/expected solution is - could you explain a little more. It appears that the solution I suggested is what you're saying is cumbersome?
Categories
Find more on Simulink Coder 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!