Initialise property with simulink.bus information located in sldd
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ludo Houben
am 16 Okt. 2023
Kommentiert: Ludo Houben
am 27 Okt. 2023
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
0 Kommentare
Akzeptierte Antwort
Poorna
am 27 Okt. 2023
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.open” function.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 “getSection” function 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”, and “getValue”, please refer to the following documentation.
Hope this Helps!
Best Regards,
Poorna.
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Manage Design Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!