Access DataStore-Variables from s-function

4 ビュー (過去 30 日間)
Henning
Henning 2021 年 7 月 1 日
コメント済み: Henning 2025 年 3 月 11 日
Hello,
ich would like to access datastore-variables directly from s-functions. The datastore references a signal-object (with an underlying nested bus-object-structure). As these structures are represented as nested c-structures (with names equal to the bus-object-structure) it would be easy to access them directly from the c-code. I found a function called 'mexGetVariablePtr()', however I am not sure whether this the the correct way, neither I know how to use this function (if it is the correct one).
Thanks a lot for you help in advance.
Regards
Henning
  2 件のコメント
ValenStein
ValenStein 2025 年 3 月 11 日
Hi Henning,
I am facing the same issue. Have you found a solution for it?
Best, Valentin
Henning
Henning 2025 年 3 月 11 日
One solution is described below.
Another solution might be to use signal-objects, which reference the relevant bus-object (Simulink.Signal;). Set signal-object property Code-Generation > Storage Class to Exported Global. Set bus-object property Code-Generation > Data-Scope to Exported. Doing that you should be able the access the signal-instance anywhere in your code as it is provided as global variable inside the model's c-code. Good luck.

サインインしてコメントする。

回答 (1 件)

Snehal
Snehal 2025 年 2 月 17 日
Hello,
I understand that you are trying to access DataStore Variables from S-functions in Simulink.
Using the ‘mexGetVariablePtr()’ function for accessing Simulink datastore variables directly from S-functions is not typically recommended because this function is a part of the MATLAB API for MEX files and is used to obtain pointers to variables in the MATLAB workspace. You can use Simulink API functions for the concerned use case.
The workflow that you can follow to access DataStore Variables using the Simulink API in S-function is:
  1. Assuming datastore variables and corresponding bus objects are already defined, use a Data Store Memory block in Simulink to specify the storage location
  2. Include necessary headers such as ‘simstruc.h’ and define C structures that match the bus object hierarchy
  3. Use ‘DWork’ vectors to manage data and ‘ssGetDWork’ to obtain pointers to the datastore memory
  4. Implement ‘mdlOutputs’ to read from and write to the datastore variables
You may refer to the following documentation links for more information:
Hope this helps.

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by