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!