How can I get the port name of a C-MEX S-function in Simulink?
28 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 11 Jun 2019
I would like an example that explains how to get the port name of a C-MEX S-function in Simulink.
Accepted Answer
MathWorks Support Team
on 11 Jun 2019
Edited: MathWorks Support Team
on 11 Jun 2019
This answer was flagged by Ramasandeep
Following is an example of how to obtain the port name of a C-MEX S-function in Simulink.
If you open up the callbacks of the S-function block in the attached model, you will notice the following lines in the 'InitFcn':
q=get_param('bsp/my_block','PortHandles');
portname=get_param(q.Inport,'Name');
Here the first line gets the port handles of the S-function block and the second line assigns the input port name of the S-function to the variable “portname”. The string variable “portname” is passed as a parameter into the S-function.
If you open up the attached S-function source file, you will notice the following lines in mdlOutputs:
buflen = mxGetN((ssGetSFcnParam(S, 0)))*sizeof(mxChar)+1;
Port_name = mxMalloc(buflen);
status = mxGetString((ssGetSFcnParam(S, 0)),Port_name,buflen);
mexPrintf("The Input Port Name is - %s\n ", Port_name);
Here the first two lines allocate memory for the string parameter that is being passed into the S-function. Then you would use "mxGetString" to store this string in a Character array. In this example the parameter is being stored in a "char *" called "Port_name" . The parameter "buflen" will be the length of this string.
0 Comments
More Answers (0)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!