필터 지우기
필터 지우기

Add Adapter programatically to system composer model

조회 수: 12 (최근 30일)
Andreas Madlinger
Andreas Madlinger 2023년 8월 17일
편집: Josh Kahn 2023년 8월 22일
Hello community,
i am trying to add an interface adapter to a system composer architecture programatically. I only can add components using addcomponent().
How is it possible to add a adaoter or do i need to convert the component into an adapter in some way? I am lost at the moment.
Thanks in advance!
Best Regards Andreas

답변 (1개)

Josh Kahn
Josh Kahn 2023년 8월 22일
편집: Josh Kahn 2023년 8월 22일
There is no API for creating adapters but you can create a component that performs the same actions using the SourceElement and DestinationElement Name-Value Arguments of the connect command. Here is an example:
% Load the architecture model and get the architecture where you want to
% add the components (in this case, the top-level).
a1Model = systemcomposer.loadModel('a1');
a1Architecture = a1Model.Architecture;
% Get the handles of the components and ports to be connected
txLeft = getComponent(a1Architecture, 'TX_Left');
txLeftOut = getPort(txLeft, 'TX_Out');
txRight = getComponent(a1Architecture, 'TX_Right');
txRightOut = getPort(txRight, 'TX_Out');
rx = getComponent(a1Architecture, 'RX');
rxIn = getPort(rx, 'RX_In');
% Create a component that will act as the adapter and add its architecture
% ports.
adapter = addComponent(a1Architecture, 'MyAdapter');
addPort(adapter.Architecture, 'TX_Out_Left', 'in');
addPort(adapter.Architecture, 'TX_Out_Right', 'in');
addPort(adapter.Architecture, 'RX_In', 'out');
% Get the corresponding component ports of the new adapter architecture ports.
adapterTXLeft = getPort(adapter, 'TX_Out_Left');
adapterTXRight = getPort(adapter, 'TX_Out_Right');
adapterRX = getPort(adapter, 'RX_In');
% Connect the component ports together
connect(txLeftOut, adapterTXLeft)
connect(txRightOut, adapterTXRight)
connect(adapterRX, rxIn)
% Clean up the diagram
Simulink.BlockDiagram.arrangeSystem('a1')
% Create the internal mappings inside of the architecture of the adapter.
% Could also have saved these from the return of the addPort command.
adapterTXLeftA = adapterTXLeft.ArchitecturePort;
adapterTXRightA = adapterTXRight.ArchitecturePort;
adapterRXA = adapterRX.ArchitecturePort;
connect(adapterTXLeftA, adapterRXA, DestinationElement='TX_Left')
connect(adapterTXRightA, adapterRXA, DestinationElement='TX_Right')
% Clean up the diagram
Simulink.BlockDiagram.arrangeSystem('a1/MyAdapter')
Let us know if you have any other questions!
Josh

카테고리

Help CenterFile Exchange에서 System Composer에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by