share memory address of variable among multiple s-functions

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

I suspect that you are implementing in C or C++?
Yep it is in C/C++ S-FUNCTION
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.

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

답변 (1개)

Qiu Xiaojie
Qiu Xiaojie 2019년 7월 4일

0 개 추천

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

chong cao
chong cao 2019년 7월 6일
편집: chong cao 2019년 7월 6일
Hi, Xiaojie
This is solved by employing a dynamic link library (DLL). You can create a dll file by using the same compiler as you use in Matlab. You can just defiine the variable you need to share. Then call this dll in your s-functions.
Multiple s-function instances will visit this dll and update the variable.
That is how I solve this problem. There could be some other ways, but I use this.
Thanks
Hi Chong,
Thank you very much for your answer! I solved this problem by using the method below:
Best Regards

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

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

태그

질문:

2017년 3월 13일

댓글:

2019년 7월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by