Add Adapter programatically to system composer model

16 visualizaciones (últimos 30 días)
Andreas Madlinger
Andreas Madlinger el 17 de Ag. de 2023
Editada: Josh Kahn el 22 de Ag. de 2023
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

Respuestas (1)

Josh Kahn
Josh Kahn el 22 de Ag. de 2023
Editada: Josh Kahn el 22 de Ag. de 2023
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

Categorías

Más información sobre System Composer en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by