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
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,
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
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.
'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
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.
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?
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
sl...@mathworks.com
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.
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');
Regards,
Mick.
"Grant Pitel" <pi...@pcka.com> wrote in message <gttpsk$hu4$1...@fred.mathworks.com>...
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