How to connect ports with system composer using the dot notation for buses programmatically?

Hi! I would like to connect ports like in the picture below, using the bus dot notation.
Note that message1 and message2 are signals within a bus.
I am able to do it by hand, how to do it programmatically?
Thanks!

답변 (1개)

Josh Kahn
Josh Kahn 2023년 10월 17일
Use the SourceElement and DestinationElement arguments of the connect API:
Regards,
Josh

댓글 수: 6

Hi! Thanks for the answer!
Can you make a code example given the picture in my question?
Best regards,
Enrico
Sure:
archModel = systemcomposer.createModel('MyArchitecture');
open(archModel);
interfaceDictionary = archModel.InterfaceDictionary;
interfaceMyInterface = addInterface(interfaceDictionary, 'MyInterface');
addElement(interfaceMyInterface, 'M1');
addElement(interfaceMyInterface, 'M2');
rootArchitecture = archModel.Architecture;
architecturePortMessageBus = addPort(rootArchitecture, 'MessageBus', 'in');
setInterface(architecturePortMessageBus, interfaceMyInterface);
componentMessageProcessing = addComponent(rootArchitecture, 'MessageProcessing');
architecturePortM1 = addPort(componentMessageProcessing.Architecture, 'M1_In', 'in');
architecturePortM2 = addPort(componentMessageProcessing.Architecture, 'M2_In', 'in');
componentPortM1 = getPort(componentMessageProcessing, 'M1_In');
componentPortM2 = getPort(componentMessageProcessing, 'M2_In');
connect(architecturePortMessageBus, componentPortM1, SourceElement='M1');
connect(architecturePortMessageBus, componentPortM2, SourceElement='M2');
Thank you so much.
I am just wondering: in my hand-done solution I didn't modify the interfaces of my model. Actually my model doesn't have any ínterface dictionary at all.
Is it possible to do it via a script in the same way? I mean without the use of interfaces.
Thanks!
Enrico
Hi Enrico,
It will work without defining a shared interface too.. The only difference is that it automatically adds the elements to the port as an owned interface (defined locally on the port instead of a data dictionary).
By the way, all architecture models have interface dictionaries, either stored locally within the model (default) or linked to an external dictionary. The added benefit of using an external dictionary is that if a change is made, it will automatically propagate to all models that are referencing that dictionary (single source of truth).
Josh
archModel = systemcomposer.createModel('MyArchitecture');
open(archModel);
% interfaceDictionary = archModel.InterfaceDictionary;
% interfaceMyInterface = addInterface(interfaceDictionary, 'MyInterface');
% addElement(interfaceMyInterface, 'M1');
% addElement(interfaceMyInterface, 'M2');
rootArchitecture = archModel.Architecture;
architecturePortMessageBus = addPort(rootArchitecture, 'MessageBus', 'in');
% setInterface(architecturePortMessageBus, interfaceMyInterface);
componentMessageProcessing = addComponent(rootArchitecture, 'MessageProcessing');
architecturePortM1 = addPort(componentMessageProcessing.Architecture, 'M1_In', 'in');
architecturePortM2 = addPort(componentMessageProcessing.Architecture, 'M2_In', 'in');
componentPortM1 = getPort(componentMessageProcessing, 'M1_In');
componentPortM2 = getPort(componentMessageProcessing, 'M2_In');
connect(architecturePortMessageBus, componentPortM1, SourceElement='M1');
connect(architecturePortMessageBus, componentPortM2, SourceElement='M2');
Hi Josh, I have a further question regarding these architecture ports and dot notation for buses. I have a simple architecture, and I want to create an Input/Output excel file automatically through a Matlab script.
My problem is that I cannot find a way to get which PDU inside the CAN1 bus is connected to which PDU in CAN2. This is, I cannot get the connections I made inside the MappingBlock. Through Matlab commands I am able to get all the ports and all the components, and inside I can see the connections between CAN1 and the CAN2 PDUs, but not the specific CAN1 PDUs that are linked to the ones in CAN2. Also I am able to see which CAN1 PDUs are selected, however not to which CAN2 PDUs they are connected. Could you help me with this?
modelName = "Arch";
model = systemcomposer.openModel(modelName);
arch = get(model, modelName);
load_system(modelName);
open_system(modelName);
MappingBlock = arch.Components(1,3);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 System Composer에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 10월 16일

댓글:

2024년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by