필터 지우기
필터 지우기

Generic S function for communication with external application

조회 수: 3 (최근 30일)
Ashish Vijay
Ashish Vijay 2011년 9월 14일
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

답변 (3개)

Kaustubha Govind
Kaustubha Govind 2011년 9월 14일
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.
  댓글 수: 1
Ashish Vijay
Ashish Vijay 2011년 9월 15일
Thanks for your help. Sorry for less information.
1) Basically I don't know too much about C/C++. I will see the COM server and other way. Thanks for your help and suggestion.
2) Yes I used real time as loosely. I mean from real time that first some application will run and then its give the data to simulation. Then only simulation should run. Then simulations should give the result. Data should not be losing and every time simulation only runs when data is there or it should be pause. It's more like a handshaking between MATALB and external application.
3) Thanks for your advice. I just want to have data type and complexity in the start as param to S function.
What I am planning is I should give data type, complexity and dimension as input to S-function in the param section. Then run the Simulink from the outside application which will give the data and take from Simulink. Simulink control I want to do with the help of Matlab engine. And as you suggest that file exchange can be used I will look on that. Thanks for your help. Please provide me further ideas that will be appreciated from my side.

댓글을 달려면 로그인하십시오.


Jonathan
Jonathan 2011년 10월 13일
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
Kaustubha Govind
Kaustubha Govind 2011년 10월 14일
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
Jonathan 2011년 10월 15일
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

카테고리

Help CenterFile Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by