How can I get the port name of a C-MEX S-function in Simulink?
32 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2009-6-27
编辑: MathWorks Support Team
2019-6-11
I would like an example that explains how to get the port name of a C-MEX S-function in Simulink.
采纳的回答
MathWorks Support Team
2019-6-11
编辑:MathWorks Support Team
2019-6-11
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!