How can I get the port name of a C-MEX S-function in Simulink?

3 ビュー (過去 30 日間)
MathWorks Support Team
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
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 件)

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by