Buses as inputs/outputs in C MEX S-Functions
9 views (last 30 days)
Hello, I have a question:
Is it possible to make a hand-written C S-Function which handles with buses as inputs/outputs? My buses are composed by different type signals.
I need to do it manually, I cannot use the S-Function Builder. Is there any way to do it? Maybe with the legacy code tool?
If it is possible, it would be great if someone could provide me a little example.
My software version is Simulink 7.0 (R2007b).
Thanks in advance,
Kaustubha Govind on 11 May 2011
There is actually a demo titled "Using Buses with Legacy Functions Having Structure Arguments" that shows how to use the Legacy Code Tool to generate S-function wrappers with input/output bus signals. You can type "showdemo sldemo_lct_bus_script" at the MATLAB prompt to see it.
For your future reference, the S-function Builder can also generated S-functions with input or output buses when you configure the "Bus" and "Bus Name" columns in the Input/Output ports pane (type "sfbuilder_bususage" at the MATLAB prompt to see an example).
Guy Rouleau on 12 May 2011
Yes it is possible.
What I recommend is to use the S-Function builder as a starting point. Use the S-Function Builder to generate a basic s-function with an architecture similar to what you need. Then throw the S-function Builder block away and call this s-function from the S-function block.
This will give you a good example as a starting point and you can modify it manually as you wish and tell everyone you wrote the whole thing yourself;-)
Riccardo Spica on 10 May 2014
I am trying to develop an s-function with a bus signal as output. I managed to do that using the sfunction builder. In normal mode everything works but if I try external mode or rapid accelerator mode I get the following error:
The model that you are trying to run in External mode does not match the application running on your target. Rebuild the model, run it on your target, and start External mode simulation again.
I have the same error also running the example sfbuilder_bususage. Any hint? Thanks in advance.