필터 지우기
필터 지우기

Buses as inputs/outputs in C MEX S-Functions

조회 수: 6 (최근 30일)
Iban
Iban 2011년 5월 11일
댓글: Amittai Aviram 2017년 5월 8일
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

답변 (4개)

Kaustubha Govind
Kaustubha Govind 2011년 5월 11일
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
Iban
Iban 2011년 5월 17일
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?

댓글을 달려면 로그인하십시오.


Guy Rouleau
Guy Rouleau 2011년 5월 12일
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
Amittai Aviram
Amittai Aviram 2017년 5월 8일
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"?

댓글을 달려면 로그인하십시오.


Iban
Iban 2011년 5월 16일
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
Kaustubha Govind
Kaustubha Govind 2011년 5월 18일
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?

댓글을 달려면 로그인하십시오.


Riccardo Spica
Riccardo Spica 2014년 5월 10일
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!

Translated by