Initialise property with simulink.bus information located in sldd
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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.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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Manage Design Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!