How to access existing variable with Data Store Read in Simulink?

조회 수: 1 (최근 30일)
Csaba
Csaba 2022년 3월 8일
편집: Shubham 2024년 9월 11일
I use a third party c library with my Simulnk model as Custom Code. I'd like to access a global variable exported in this library with a Data Store Read block from the Simulink model. However I don't know how to tell the Data Store Memory block that it is an already existing variable. It always exports the definition no matter what, and also initializes the variable with de default values. How can it be achieved? Thanks!

답변 (1개)

Shubham
Shubham 2024년 9월 11일
편집: Shubham 2024년 9월 11일
Hey Csaba,
I understand that you want to use external C/C++ code to import certain variables to be later used by Data Store Memory block.
In order to use the global variables defined in the external code, the recommended practice is to use a Stateflow chart in order to call your function and to access the variables. You would need to write C/C++ code in the chart so that during simulation, the model reads and writes to the variables. These global variables can be converted into MATLAB variables and then used to initialize Data Store Memory block.
Once you can access the variables defined externally, you can use them to modify the Data Store Memory block.
For more information upon accessing the variables from an external C/C++ code into your Simulink model, refer to the "Import External Code into Model" section of the following documentation: https://www.mathworks.com/help/rtw/ug/generate-code-for-interfacing-data-with-external-code.html#:~:text=Integration%20Workflow.-,Import%20External%20Code%20into%20Model,-To%20exchange%20data
I hope this helps!

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by