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

1 vue (au cours des 30 derniers jours)
Csaba
Csaba le 8 Mar 2022
Modifié(e) : Shubham le 11 Sep 2024
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!

Réponses (1)

Shubham
Shubham le 11 Sep 2024
Modifié(e) : Shubham le 11 Sep 2024
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!

Catégories

En savoir plus sur Event Functions dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by