Access DataStore-Variables from s-function

조회 수: 7 (최근 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 CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by