Generic S function for communication with external application
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I want to develop S functions for reading and writing data for MATALB Simulink system to a different application like C/C++ outside program.
Read Data S- Function should able to read data from outside application like some C/C++ programs and can give that data to simulation.
In the same time write data S function should give the simulink data to outside application.
These data flow should be real time like first outside application run and generate data then give to read S function. Then simulation should run and give the data to application back. Then Simulation should pause till new data arrive from application.
These data type should be generic and can change dynamically.
Can some body sugest me some example or way to do that. Thanks
0 comentarios
Respuestas (3)
Kaustubha Govind
el 14 de Sept. de 2011
Your question does not provide all the information needed:
1) What mode of communication/interface does your external application provide - Is it just a function that needs to be invoked by the S-function? Is it a COM server? - either way, since S-functions can call any generic C/C++ code, if you can write a C application to achieve this communication, you can simply plug that C code into an S-function. (Search File Exchange for any existing user submissions once you have determined your interfacing technique).
2) Do you use the phrase "real-time" loosely? Note that none of the standard host operating systems (Windows, Linux, etc.) are exactly "real-time operating systems". So the speed of communication between any two processes is governed by the priority that they get, CPU load, etc. However, if you only meant that they should be able to continuously communicate to send/receive data, but not necessarily within a definite interval of time (for example, if you were reading from a buffer that is written to at a certain rate, you might need to worry about your application being real-time - although in most cases, if your application runs slow enough you can achieve a pseudo real-time communication).
3) "These data type should be generic and can change dynamically" - in general, the C code that you write to interface should be able to handle this. However, if you plan to somehow output this data directly from the S-function (or store it as a state), you need to be careful about how to configure your S-function. Note that signal attributes like datatype and complexity cannot change during simulation.
Jonathan
el 13 de Oct. de 2011
Goodday,
I am doing something similar to Mr. Vijay. I am creating an environment which should allow a user to send input data from an MFC application to a simulink block diagram control system( multiple inputs). The system should then send the output values (multiple outputs) back to the MFC application. This needs to be done in 'real time' and by that I quote Ms. Govind - " be able to continuously communicate to send/receive data, but not necessarily within a definite interval of time".
I am not sure of the best way to approach this as I new to Simulink and do not possess any experience in writing S functions. What is the best way to approach linking the application and Simulink for data transfer?
Any example code with comments would be useful. Thanks in advance.
1 comentario
Kaustubha Govind
el 14 de Oct. de 2011
Jonathan: See the documentation here for examples to integrate external C code into Simulink using an S-function: http://www.mathworks.com/help/toolbox/simulink/sfg/brgo03i-6.html#brgo03i-7
Note that there are two tools (S-Function Builder and Legacy Code Tool) that can automatically generate an S-function if you can provide the function interface that needs to be called from the S-function. Alternatively, you can write one manually.
Jonathan
el 15 de Oct. de 2011
Thank you very much Kaustubha, I really appreciate the guidance. I will look at this and try to implement the S function after I have finished coding the GUI.
Regards
0 comentarios
Ver también
Categorías
Más información sobre Simulink Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!