S-function interfacing problem: Storing a C-struct in a global data store?

Hi all,
General info: - Matlab version: 7.10.0. R2010a (Simulink)
I have a s-function (C-code) which expects a C-struct as an input. This s-function is called several times during processing. The required C-struct is read from a file in the initiating procedure. The struct is variable in length.
And now my questions:
1. How am I supposed to store this C-struct in a global buffer?
2. And how do I feed this struct back into the s-function?
3. Do I need some kind of struct serializing/deserializing function? Or can I somehow just pass a pointer (memory location) to the s-function?
Since I'm new to Simulink, example code is very much appreciated.
Thanks in advance.

回答 (2 件)

Mark
Mark 2011 年 2 月 7 日

1 投票

Simulink itself doesn't read C header files, so you will need to make a Simulink.Bus object that describes the structure to Simulink. From there, there S-functions have a bus API for accessing the elements of the bus coming from/going to Simulink. You will need to use this API to access the bus elements and then populate an instance of the C structure that you have inside of your S-function. This can be a little bit tedious, so I would recommend creating the Simulink.Bus objects, and using the Legacy Code Tool to create an S-function that uses the bus objects as inputs and/or outputs.
The code generated by the Legacy Code Tool will give you a good starting point/example for how to access the bus object.
Oyun
Oyun 2011 年 2 月 8 日

0 投票

Hi there,
thanks for your answer. Yes, i have already used LCT to generate my S-function. But what if you are not allowed to use bus objects due to embedded issues?
Thanks, Oyun

1 件のコメント

Mark
Mark 2011 年 2 月 8 日
Could you clarify what you mean by "embedded issues"? In general terms, bus objects turn into structures during code-generation, and it sounds like you are already using structures. Bus objects are really the only way to accommodate C structures, so all we can really do is try to minimize the impact of whatever issues you have in mind.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink Coder についてさらに検索

製品

質問済み:

2011 年 2 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by