Clear Filters
Clear Filters

데이터 딕셔너리 파일과 시뮬링크 모델의 BUS데이터 연결

7 views (last 30 days)
kiseon sim
kiseon sim on 25 Mar 2024
Commented: Angelo Yeo on 12 Apr 2024
시뮬링크 스켈레톤 모델을 자동 생성하려는 코드를 만들고자 합니다.
1)시뮬링크 In bus element와 Out bus element 생성
2)데이터 딕셔너리의 Bus 신호들 생성
3)시뮬링크 모델에 sldd 파일을 불러오기, slx 파일의 bus element의 Data type을 sldd 파일의 Bus 신호를 할당하기
1)번과 과 2)번은 m파일로 작성을 가능한걸 확인했습니다.
3)번의 경우는 검색을 하여도 잘 찾지 못하겠고. slx 파일이나 sldd 파일내의 xml 파일에도 해당 정보를 찾기가 힘듦더라구요
어떤식으로 모델에 sldd 파일을 연동시키고 sldd파일 bus 신호를 slx 파일과 연동시킬수 있습니까?
(대량의 데이터를 다루기때문에 자동화가 필요합니다.)

Accepted Answer

Angelo Yeo
Angelo Yeo on 25 Mar 2024
간단하게 정리해보았습니다. 목적에 맞게 변형하여 사용하시면 도움이 될 것으로 생각합니다. 추가적인 도움이 필요하시다면 기술지원팀에 연락해보셔도 좋을 것 같습니다.
%% Open a new model namde "BusInterfaces"
mdl = "BusInterfaces";
new_system(mdl);
open_system(mdl);
%% API to Create an In Bus Element
h = add_block("simulink/Ports & Subsystems/In Bus Element", ...
"BusInterfaces/InBusElement", ...
PortName="Sources", ...
Element="sinusoidal.sine");
%% Creating a sample bus
elems(1) = Simulink.BusElement;
elems(1).Name = 'Chirp';
elems(2) = Simulink.BusElement;
elems(2).Name = 'Sine';
Sinusoidal = Simulink.Bus;
Sinusoidal.Elements = elems;
%% Storing new entries into SLDD
dictName = 'myDatadictionary_ex_API.sldd';
if ~exist(dictName, 'file')
myDictObj = Simulink.data.dictionary.create(dictName);
else
myDictObj = Simulink.data.dictionary.open(dictName);
end
dDataSectObj = getSection(myDictObj, 'Design Data');
addEntry(dDataSectObj, 'myNewEntry', Sinusoidal)
myDictObj.close;
%% Link the dictionary to the model
set_param(mdl, 'DataDictionary', dictName)
%% Assign data type of bus element
% get_param(h, "Element")
InBusElements = find_system(gcs,'BlockType', 'Inport', 'IsBusElementPort', 'on');
len = numel(InBusElements);
if ~isempty(len)
for n = 1:len
set_param(InBusElements{n}, 'OutDataTypeStr', 'Bus: myNewEntry')
end
end
아래는 결과물 스크린샷입니다.
  2 Comments
kiseon sim
kiseon sim on 11 Apr 2024
감사합니다. 문제가 잘 해결되었습니다 ㅎㅎㅎ
Angelo Yeo
Angelo Yeo on 12 Apr 2024
도움 되셨다면 답변 채택을 부탁드립니다 😊

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!