Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Access bus signal names in S-function

Subject: Access bus signal names in S-function

From: Mick H

Date: 9 Oct, 2007 07:50:42

Message: 1 of 17

I have used a bus creator in my model to create a set of
(named) signals. The output is passed to an S-function
written by me.

Is there a way to access/read the individual bus signal
names from within the S-function?

Thanks for any help.

Mick.

Subject: Access bus signal names in S-function

From: riccardo

Date: 10 Oct, 2007 08:43:04

Message: 2 of 17

"Mick H" <mick.nospam@mickhodgkins.com> wrote in message
<fefbsi$9go$1@fred.mathworks.com>...
> I have used a bus creator in my model to create a set of
> (named) signals. The output is passed to an S-function
> written by me.
>
> Is there a way to access/read the individual bus signal
> names from within the S-function?
>
> Thanks for any help.
>
> Mick.

Hi Mick,
what do you want to do, actually ?
I don't know whether signal labelling is traced anywhere
within the simstruct structure.
But it's certainly possible to write an m-function to
browse your s-function block connections in the Simulink
model, and retrieve the data you need.
This m-function can be called by your s-function via
mexCallMatlab when the model starts/initialises, or it can
be used as a callback function, or as a mask initialisation
function.
The choice about how to do it depends on your answer to the
question above.
HTH
Riccardo

Subject: Access bus signal names in S-function

From: Mick H

Date: 11 Oct, 2007 07:32:27

Message: 3 of 17

Riccardo,

Thanks for your reply.

I want to take the input signals and save them in a
variable structure, with the signal names used as variable
names within the structure. I then save the structure in
the workspace for post-processing.

At the moment I am using a toWorkspace block to save the
signals, then running a script to produce the structure
required for the post-processor with the names hard-coded
into the script. If I add a signal or change a signal
name, I have to modify the script. I thought I should be
able to build an S-function to read the signal names and
produce the structure for me.

Mick.

> Hi Mick,
> what do you want to do, actually ?
> I don't know whether signal labelling is traced anywhere
> within the simstruct structure.
> But it's certainly possible to write an m-function to
> browse your s-function block connections in the Simulink
> model, and retrieve the data you need.
> This m-function can be called by your s-function via
> mexCallMatlab when the model starts/initialises, or it
can
> be used as a callback function, or as a mask
initialisation
> function.
> The choice about how to do it depends on your answer to
the
> question above.
> HTH
> Riccardo
>

Subject: Access bus signal names in S-function

From: riccardo

Date: 11 Oct, 2007 08:30:35

Message: 4 of 17

"Mick H" <mick.nospam@mickhodgkins.com> wrote in message
<fekjib$5ev$1@fred.mathworks.com>...
> Riccardo,
>
> Thanks for your reply.
>
> I want to take the input signals and save them in a
> variable structure, with the signal names used as
variable
> names within the structure. I then save the structure in
> the workspace for post-processing.
>
> At the moment I am using a toWorkspace block to save the
> signals, then running a script to produce the structure
> required for the post-processor with the names hard-coded
> into the script. If I add a signal or change a signal
> name, I have to modify the script. I thought I should be
> able to build an S-function to read the signal names and
> produce the structure for me.
>
> Mick.
>
> > Hi Mick,
> > what do you want to do, actually ?
> > I don't know whether signal labelling is traced
anywhere
> > within the simstruct structure.
> > But it's certainly possible to write an m-function to
> > browse your s-function block connections in the
Simulink
> > model, and retrieve the data you need.
> > This m-function can be called by your s-function via
> > mexCallMatlab when the model starts/initialises, or it
> can
> > be used as a callback function, or as a mask
> initialisation
> > function.
> > The choice about how to do it depends on your answer to
> the
> > question above.
> > HTH
> > Riccardo
> >
>

Mick,
I see.
No need of any additional s-function or m-function, then.
Just modify your script so that it can parse the model and
pick up the signal names from it.
Even simpler if you make an m-function out of it, to which
you pass the Simulink path of the relevant block(s).
See the help for "find_system" and related functions.
Riccardo

Subject: Access bus signal names in S-function

From: Mick H

Date: 20 Nov, 2007 07:19:58

Message: 5 of 17


>
> Mick,
> I see.
> No need of any additional s-function or m-function, then.
> Just modify your script so that it can parse the model
and
> pick up the signal names from it.
> Even simpler if you make an m-function out of it, to
which
> you pass the Simulink path of the relevant block(s).
> See the help for "find_system" and related functions.
> Riccardo

Thanks. Parsing the model is a partial solution and
certainly an improvement on what I am doing now. However,
it would still be more flexible to be able to access the
signal names from within an S-function and write a
structure directly to the workspace. This "toWorkspace"
block could be reused in many different models and would
be much more flexible than using a model parser.

Is it possible?

Mick.

Subject: Access bus signal names in S-function

From: riccardo

Date: 27 Nov, 2007 08:45:07

Message: 6 of 17

"Mick H" <mick.nospam@mickhodgkins.com> wrote in message
<fhu1qu$2h3$1@fred.mathworks.com>...
>
> >
> > Mick,
> > I see.
> > No need of any additional s-function or m-function,
then.
> > Just modify your script so that it can parse the model
> and
> > pick up the signal names from it.
> > Even simpler if you make an m-function out of it, to
> which
> > you pass the Simulink path of the relevant block(s).
> > See the help for "find_system" and related functions.
> > Riccardo
>
> Thanks. Parsing the model is a partial solution and
> certainly an improvement on what I am doing now. However,
> it would still be more flexible to be able to access the
> signal names from within an S-function and write a
> structure directly to the workspace. This "toWorkspace"
> block could be reused in many different models and would
> be much more flexible than using a model parser.
>
> Is it possible?
>
> Mick.
>

Sorry I wasn't very clear.
Use an m-function, sketched above, as a part of your s-fcn
block initialisation process. DON'T parse the entire model.
Get hold of the relevant signal lines and their properties,
with commands like:
- ph = get_param( <blkHandle>, 'porthandles' )
- lh = get_param( ph.Inport(<index>), 'line' )
- lName = get_param( lh, 'Name' )
Be careful only with the implication of running the
function as part of the block/mask initialisation.
It may turn out easier/less messy to call the m-function
from the s-function mdlStart method, say, after block
properties have been set.
Hope it helps.
Riccardo

Subject: Access bus signal names in S-function

From: Mick H

Date: 7 Apr, 2008 05:32:02

Message: 7 of 17


> Get hold of the relevant signal lines and their
properties,
> with commands like:
> - ph = get_param( <blkHandle>, 'porthandles' )
> - lh = get_param( ph.Inport(<index>), 'line' )
> - lName = get_param( lh, 'Name' )
> Be careful only with the implication of running the
> function as part of the block/mask initialisation.
> It may turn out easier/less messy to call the m-function
> from the s-function mdlStart method, say, after block
> properties have been set.
> Hope it helps.
> Riccardo
>

Thanks Riccardo. I've come back to this after some time
away. With your help I have a function working which takes
a single input. I've used the get_param function as you
indicated to get the signal name from the input port/line.

I have not been able to find the parameters to use to
access the signal names if I have a bus of many signals
entering through the inport. Is there a way to do this?

e.g. something like:-

 - ph = get_param( <blkHandle>, 'porthandles' )
 - is = get_param( ph.Inport(<index>), 'somehandle' )
 - is = get_param( <somehandle>, 'InputSignalNames' )

I can access the InputSignalNames from the originating
BusCreator block if I know its handle but is there a way
to get the names without searching for the originating
block?

Thanks for your help.

Mick.

Subject: Access bus signal names in S-function

From: riccardo

Date: 8 Apr, 2008 09:19:02

Message: 8 of 17

"Mick H" <mick.nospam@mickhodgkins.com> wrote in message
<ftcbki$5ea$1@fred.mathworks.com>...
>
> > Get hold of the relevant signal lines and their
> properties,
> > with commands like:
> > - ph = get_param( <blkHandle>, 'porthandles' )
> > - lh = get_param( ph.Inport(<index>), 'line' )
> > - lName = get_param( lh, 'Name' )
> > Be careful only with the implication of running the
> > function as part of the block/mask initialisation.
> > It may turn out easier/less messy to call the m-
function
> > from the s-function mdlStart method, say, after block
> > properties have been set.
> > Hope it helps.
> > Riccardo
> >
>
> Thanks Riccardo. I've come back to this after some time
> away. With your help I have a function working which
takes
> a single input. I've used the get_param function as you
> indicated to get the signal name from the input
port/line.
>
> I have not been able to find the parameters to use to
> access the signal names if I have a bus of many signals
> entering through the inport. Is there a way to do this?
>
> e.g. something like:-
>
> - ph = get_param( <blkHandle>, 'porthandles' )
> - is = get_param( ph.Inport(<index>), 'somehandle' )
> - is = get_param( <somehandle>, 'InputSignalNames' )
>
> I can access the InputSignalNames from the originating
> BusCreator block if I know its handle but is there a way
> to get the names without searching for the originating
> block?
>
> Thanks for your help.
>
> Mick.
>
>
>

Mick,
I don't think it's possible, because a line object doesn't
hold that sort of info - not in versions I'm using, at
least. You have to crawl back to the Bus block, I'm afraid.

Subject: Access bus signal names in S-function

From: Peter

Date: 24 Dec, 2008 17:49:01

Message: 9 of 17

From MathWorks tech support (Akshat Kapadia):

'Exploring buses inside C++ S-Functions'.

There is a solution on our website which talks about dealing with bus input to an S-function. The solution uses an example model to demonstrate performing different operations on the signal present in the bus input. Please refer to the following link for more information on this

http://www.mathworks.com/support/solutions/data/1-6XZSQC.html?solution=1-6XZSQC

Subject: Access bus signal names in S-function

From: Peter

Date: 24 Dec, 2008 17:56:02

Message: 10 of 17

Using the following sequence, I can get the lines being passed through a mux:

lines = get_param('Dimensions/Bus Creator', 'LineHandles')

get_param(lines.Inport, 'Name')

Where 'Dimensions/Bus Creator' is the full pathname for the mux.

However, this does not give me the full structure of a compound bus.

If I double-click on the mux, the Function Block Parameters dialog appears. Within that dialog is the entire compound bus structure, if all sub-buses are expanded.

Is there a way to get this structure in text form, with all indentations preserved?

Thank you for whatever insights you can offer.

Subject: Access bus signal names in S-function

From: Grant Pitel

Date: 7 May, 2009 03:09:01

Message: 11 of 17

Bump on the topic.

Do the Mathworks GURUS have any advice on this basic and essential task? Obviously, it can be done, as the Bus Creator block does just that, it gets the names from input buses and all its children and lists them. Unfortunately users do not have access to the GUI code that demonstrates how it should be done. Please help.

Otherwise I may have to roll up my sleeves are write a nasty recursion algorithm (YUCK). Does someone have a simple solution?

Subject: Access bus signal names in S-function

From: Grant Pitel

Date: 7 May, 2009 03:12:02

Message: 12 of 17

interesting....
busCreatorddg.m

Subject: Access bus signal names in S-function

From: Steven Lord

Date: 7 May, 2009 03:17:07

Message: 13 of 17


"Grant Pitel" <pitel@pcka.com> wrote in message
news:gttjcd$do3$1@fred.mathworks.com...
> Bump on the topic.
>
> Do the Mathworks GURUS have any advice on this basic and essential task?

No, I don't, since I don't write or work with S-functions on a regular
basis. Have you contacted Technical Support? Some of the support staff do
write and work with S-functions on a regular basis.

--
Steve Lord
slord@mathworks.com

Subject: Access bus signal names in S-function

From: Grant Pitel

Date: 7 May, 2009 03:37:00

Message: 14 of 17

Steve,
I was able to figure it out.

Inside function busCreatorddg.m (a Mathworks function) the author caches all the bus signal names in variable UserData. I iterate through the lines connected to the inport of my s-function block until I hit "Bus Creator", look in UserData, and eureka, its there.
 

Subject: Access bus signal names in S-function

From: Grant Pitel

Date: 7 May, 2009 05:00:04

Message: 15 of 17

This is seriously weird. The function busCreatorddg.m takes a Data Object input argument block (Bus Creator). The bus signals are accessed using class function BusStruct.

When you run simulations the block can only be accessed via its handle and get_param. BusStruct is not a listed paramater. However, if you ignore this, and type it any way, you get the bus signals. WEIRD. Bug? Maybe... By design? Maybe... Steve can you take this question to you hardcore simulink guys for a response. Thanks.

hLine=get_param(gcb,'LineHandles');
hSrcBlock=get(hLine.Inport,'SrcBlockHandle');
srcBlockName=get(hSrcBlock,'Name');
busSignalName=get_param(getfullname(hSrcBlock),'BusStruct');

Subject: Access bus signal names in S-function

From: Mick H

Date: 9 May, 2009 01:41:01

Message: 16 of 17

Not sure if it is of interest or not but since I started this thread I have created a simple simulink block and script that reads the bus signal names and writes bus data to a workspace structure using the signal names as the variable names. See the busToWorkspace block I've uploaded to the Mathworks community forum.

Regards,

Mick.

"Grant Pitel" <pitel@pcka.com> wrote in message <gttpsk$hu4$1@fred.mathworks.com>...
> This is seriously weird. The function busCreatorddg.m takes a Data Object input argument block (Bus Creator). The bus signals are accessed using class function BusStruct.
>
> When you run simulations the block can only be accessed via its handle and get_param. BusStruct is not a listed paramater. However, if you ignore this, and type it any way, you get the bus signals. WEIRD. Bug? Maybe... By design? Maybe... Steve can you take this question to you hardcore simulink guys for a response. Thanks.
>
> hLine=get_param(gcb,'LineHandles');
> hSrcBlock=get(hLine.Inport,'SrcBlockHandle');
> srcBlockName=get(hSrcBlock,'Name');
> busSignalName=get_param(getfullname(hSrcBlock),'BusStruct');

Subject: Access bus signal names in S-function

From: angelo

Date: 29 Jul, 2009 09:55:28

Message: 17 of 17

Hi everybody,

I'm trying to use this information about the busCreatorddg.m function to extract the signal's names entering in a bus creator block and manipulate them in a m-file function. Usually it is used with a double click on the Bus Creator but what I need is call the function in a callback function I have created (answering when signals to the bus creator are connected) and use the structure stored in the field 'block.UserData' (or, that is the same 'ud.busStruct') but I don't know how to call that...what kind of arguments? Ok the 'block' should be the Bus creator (the name or the handle?). And the 'source' parameter?

Any idea?

Thanks

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us