share memory address of variable among multiple s-functions
Ältere Kommentare anzeigen
Hello, I am implementing a communication protocol using TCP socket in simulink. I use s-functions My initial idea is to define three C s-functions, that uses the same socket. 1. communication initialization, create a socket and get connected 2. a transmit block 3. a receive block I have included a header file defining some global variables that are necessary to all the three s-functions. I want the three s-function blocks are able to these variables (access to the same memory address) However, what I found is although I use the same header file, three s-functions create different variable instances. For example, I create the socket in the initialization s-function but this socket can not be used in the transmit and receive block.
So I wonder if there is any way we can share variables among different s-functions?
3 Kommentare
Walter Roberson
am 13 Mär. 2017
I suspect that you are implementing in C or C++?
chong cao
am 15 Mär. 2017
Walter Roberson
am 15 Mär. 2017
https://www.mathworks.com/help/ecoder/examples/configuring-the-data-interface.html seems to show examples of setting up global data; and https://www.mathworks.com/help/simulink/gui/simulink-coder-options.html and https://www.mathworks.com/help/simulink/ug/using-global-data-with-the-matlab-function-block.html
I seem to remember that some of the rest comes down to the code placement model properties that you define; it would take me a bit of time to find the settings.
Antworten (1)
Qiu Xiaojie
am 4 Jul. 2019
0 Stimmen
Hallo Chong,
Did you solve this problem? If you have any idea, please tell me how to share memory across several S-Function blocks.
Thank you!
2 Kommentare
Xiaojie Qiu
am 8 Jul. 2019
Hi Chong,
Thank you very much for your answer! I solved this problem by using the method below:
Best Regards
Kategorien
Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!