S-function interfacing problem: Storing a C-struct in a global data store?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
MarkB
el 7 de Feb. de 2011
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 comentarios
Oyun
el 8 de Feb. de 2011
1 comentario
MarkB
el 8 de Feb. de 2011
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.
Ver también
Categorías
Más información sobre Event Functions en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!