Buses as inputs/outputs in C MEX S-Functions

8 views (last 30 days)
Iban
Iban on 11 May 2011
Commented: Amittai Aviram on 8 May 2017
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,
Iban

Answers (4)

Kaustubha Govind
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).
  1 Comment
Iban
Iban on 17 May 2011
Hello Kaustubha,
Thank you for answering. I do not understand very well the example provided by the "showdemo sldemo_lct_bus_script" command.
In my case, a bus is just a structure of different data which I need to compute on the "mdlOutputs" of the S-function, so I think I do not need anything like the "counterbusFcn(COUNTERBUS *u1, int32_T u2, COUNTERBUS *y1, int32_T *y2)" function that appears in that example. Do I need it? Can you give me an example/tutorial/guide of a SFunction with buses in which the data is computed in the "mdlOutputs" whithout any function definition?

Sign in to comment.


Guy Rouleau
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;-)
  1 Comment
Amittai Aviram
Amittai Aviram on 8 May 2017
Sorry--I do not understand what you mean. If you use the S-Function Builder, you must finish by clicking on "Build," which produces a binary MEX file (*.mexa64), which you can neither examine nor alter. How can you use this "as a starting point"? How can you "modify it manually"?

Sign in to comment.


Iban
Iban on 16 May 2011
Hello,
I do not understand very well the example provided by the "showdemo sldemo_lct_bus_script" command.
In my case, a bus is just a structure of different data which I need to compute on the "mdlOutputs" of the S-function, so I think I do not need anything like the "counterbusFcn(COUNTERBUS *u1, int32_T u2, COUNTERBUS *y1, int32_T *y2)" function that appears in that example.
I cannot use the S-Function Builder to make myself an example because Simulink R2007b does not allow to use buses on the input/output ports, so it would be great if someone could give me a small example of the C code of an SFunction with a bus on the input or output ports, or a tutorial/guide to do it by myself.
Thanks in advance,
Iban.
  1 Comment
Kaustubha Govind
Kaustubha Govind on 18 May 2011
Iban: Are you saying that neither your input nor your output signal is a bus? What exactly is a structure in your code? Local/Parameter data?

Sign in to comment.


Riccardo Spica
Riccardo Spica on 10 May 2014
Hello,
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.

Community Treasure Hunt

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

Start Hunting!