Initialise property with simulink.bus information located in sldd

조회 수: 4 (최근 30일)
Ludo Houben
Ludo Houben 2023년 10월 16일
댓글: Ludo Houben 2023년 10월 27일
Hi all
The code below is working as intended, however the 'ST_FB_TRIGGERBUFFER_DATARECORD' needs to be available in the base workspace. I have the definition stored in a data dictionary (FB_TriggerBuffer.sldd), how to change the code below, so it will search the definition in this data dictionary?
Thanks in advance
Ludo
classdef FB_TriggerBuffer < matlab.System
% System Flags
% =====================================
methods (Static, Access = protected)
function flag = supportsMultipleInstanceImpl(~)
flag = true;
end
end
% Properties declaration
% =====================================
% Public properties
properties (Access = public)
nWriteIndex uint16 = 1; % [] Index to the record which will be written
arrstDataBuffer = repmat(Simulink.Bus.createMATLABStruct('ST_FB_TRIGGERBUFFER_DATARECORD'),1,3); % [] Buffer holding the supplied data
stEmptyDataRecord = Simulink.Bus.createMATLABStruct('ST_FB_TRIGGERBUFFER_DATARECORD'); % [] Empty data record
end

채택된 답변

Poorna
Poorna 2023년 10월 27일
Hi Ludo,
I understand that you would like to access the definition of 'ST_FB_TRIGGERBUFFER_DATARECORD' from the data dictionary 'FB_TriggerBuffer.sldd' instead of the Base workspace.
You can follow the below steps to access data from a data dictionary:
1) Declare a class property say ‘FB_TriggerBufferObj’ and initialize it with the data dictionary object using the “Simulink.data.dictionary.openfunction.Here is the sample code for the same:
FB_TriggerBufferObj = Simulink.data.dictionary.open('FFB_TriggerBuffer.sldd')
2) To access the variable in the class methods, you can use the “getSectionfunction to retrieve the section in which the entry is stored. Then, use the “getEntry” function to retrieve the entry. Finally use the “getValue” function to obtain the value of the desired entry.Here is the sample code for the same:
dataSec = getSection(FB_TriggerBufferObj, 'Design Data');
dataEntry = getEntry(dataSec, 'ST_FB_TRIGGERBUFFER_DATARECORD');
val = getValue(dataEntry);
3) Now, you can use the retrieved value as usual in the code.
To know more about the functions Simulink.data.dictionary.open”, getSection”,getEntry”, andgetValue, please refer to the following documentation.
Hope this Helps!
Best Regards,
Poorna.
  댓글 수: 1
Ludo Houben
Ludo Houben 2023년 10월 27일
Hi Poorna
There is a small typo 'FFB_TriggerBuffer.sldd' but your answer is clear. I accepted it, although for me this solution is not working. This solution can not be used in 'code generation' simulation mode.
For others with the same issue. I solved it by running a Matlab scipt loading all used bus definitions in to base workspace.
Note: My main 'PlayGroundStructs.sldd' calls several lower level *.sldd files.
%% Load struct definition
Simulink.data.dictionary.open("PlayGroundStructs.sldd");
structEntries = find(getSection(Simulink.data.dictionary.open("PlayGroundStructs.sldd"), ...
'Design Data'), '-value', '-class', 'Simulink.Bus'); % Get all simulink.bus definitions from SLDD file
for index = 1:length(structEntries) % For all found simulink.bus definitions
assignin('base',structEntries(index).Name,getValue(structEntries(index))); % Create struct
end
clear index structEntries; % Delete temporary variables

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Manage Design Data에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by