S-function interfacing problem: Storing a C-struct in a global data store?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
MarkB
2011-2-7
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.
0 个评论
Oyun
2011-2-8
1 个评论
MarkB
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Event Functions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!