Initialise property with simulink.bus information located in sldd
조회 수: 4 (최근 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!