Discussion:
Naming the ports of a S-Function block
(too old to reply)
Ali
2009-02-04 00:23:01 UTC
Permalink
Hi all
Sorry if this has been asked before, a quick search didn't result in anything.

I have a S-Function block written in C++. This block has a variable number of ports. The port configuration data is kept in a text file which stores the port names, sizes, types, etc. In mdlInitializeSizes() my code reads the text file and parses it, creating the correct number of ports and their types/sizes. All work flawlessly. However, I would like to show the port names on the block, because when trying to connect wires to the block it is confusing which port is which. Is there a way to do so?

Thanks a lot.
Phil Goddard
2009-02-04 15:56:02 UTC
Permalink
Have a look at a recent threat for some ideas:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242073#620920

basically you need to ensure that the S-Function block is masked, and then set it to display appropriate port labels.
From the command line (in m-code) this would done using the following commands.
set_param(gcb,'Mask','on')
set_param(gcb,'MaskDisplay','port_label(''output'',1,''channel 1'')');
You'll need some mexCallMATLAB calls in your c-code to get this to work.

Phil.
Praetorian
2009-02-04 16:25:39 UTC
Permalink
Have a look at a recent threat for some ideas:http://www.mathworks.com/matlabcentral/newsreader/view_thread/242073#...
basically you need to ensure that the S-Function block is masked, and then set it to display appropriate port labels.
From the command line (in m-code) this would done using the following commands.
set_param(gcb,'Mask','on')
set_param(gcb,'MaskDisplay','port_label(''output'',1,''channel 1'')');
You'll need some mexCallMATLAB calls in your c-code to get this to work.
Phil.
Instead of using mexCallMATLAB from your S-Function I'd suggest you
write an m-file function to parse the file and set the mask display.
This function can be called from the block's Initialization pane.
Also, IMO it's better to have this m-file set mask parameters and pass
these parameters to the S-Function rather than have it parse the file
directly.
David
2009-02-06 00:33:01 UTC
Permalink
If I just want to have my S-Function name the ports when I place it in a simulink model, can I just add calls to set_param() via mexCallMATLAB in my C++ code?
If so, what do I use for the object name parameter to the set_param() function?
Phil Goddard
2009-02-06 02:57:03 UTC
Permalink
You should just be able to use gcb, which returns the name of the current block
For more info,
doc gcb
Phil.
Ali
2009-02-08 23:15:03 UTC
Permalink
Thanks for all your answers. Can you help this total newbie with mexCallMATLAB()? How can I call the following two functions:

set_param(gcb,'Mask','on')
set_param(gcb,'MaskDisplay','port_label(''output'',1,''channel 1'')');

With mexCallMATLAB()? All the examples I have seen show how to pass matrices and such, I don't know how to pass numbers or strings. Thanks a lot.
Ali
2009-02-09 12:18:02 UTC
Permalink
Update: I managed to get mexCallMATLAB() to work. I have another problem: calling "set_param(gcb,'MaskDisplay','port_label(''output'',1,''channel 1'')');" causes mdlInitializeSizes() to be called again. Basically:

1. If I call 'set_param...' within mdlInitializeSizes() I either fall into an endless loop or Simulink will complain about setting the number of output ports more than once;

2. If I call 'set_param...' within mdlSizes() or mdlOutput() it has no effect;

3. If I do a set_param(gcb,'MaskDisplay','port_label(''output'',1,''channel 1'')'); in Matlab command window it works, but when I do another one for the 2nd port the label of the first port disappears.

Is there any way around this? Thanks.

Continue reading on narkive:
Loading...