I have a subsystem in Simulink with LConn and RConn blocks, some from Simulink Electrical and others from Simscape. How can I retrieve their type info from MATLAB?
31 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a subsystem in Simulink with several LConn and RConn blocks. Some of them are from Simulink Electrical, and others are from Simscape. In Simulink, they appear as triangles or squares. How can I retrieve this information from MATLAB to determine their type?
0 Commenti
Risposte (2)
Yifeng Tang
il 19 Mar 2025
I think this will help:
myBlock = 'example/Subsystem';
port_handles = get_param(myBlock,"PortHandles")
inports = port_handles.Inport;
outports = port_handles.Outport;
PhysConnL = port_handles.LConn;
PhysConnR = port_handles.RConn;
get_param(inports(1) ,"PortType")
get_param(outports(1) ,"PortType")
get_param(outports(2) ,"PortType")
get_param(PhysConnL(1),"PortType")
get_param(PhysConnR(1),"PortType")
You'll need the attached slx file to run the code.
This gives me:
port_handles = struct with fields:
Inport: 168.0007
Outport: [179.0007 180.0016]
Enable: []
Trigger: []
State: []
LConn: 181.0010
RConn: 182.0010
Ifaction: []
Reset: []
Event: []
ans = 'inport'
ans = 'outport'
ans = 'outport'
ans = 'connection'
ans = 'connection'
0 Commenti
Simon
il 14 Ago 2025 alle 3:55
Hi,
As I understand, you want to distinguish between Simulink Electrical and Simscape LConn/RConn blocks inside your Simulink subsystem. I see it’s already been answered using get_param('PortHandles'), which is helpful for identifying the subsystem’s external ports. Additionally, using find_system allows you to identify all internal LConn and RConn blocks and determine their type and origin, you can also use the following approach:
Use find_system to search for all LConn and RConn blocks inside your subsystem, then query their ReferenceBlock and MaskType properties. This will show you whether each block is from Simscape or Simulink Electrical. For example:
subsys = 'example/Subsystem'; %use your path, run the code in MATLAB command window for the slx file
lconns = find_system(subsys, 'RegExp', 'on', 'Name', 'LConn');
rconns = find_system(subsys, 'RegExp', 'on', 'Name', 'RConn');
all_conns = [lconns; rconns];
for i = 1:length(all_conns)
blk = all_conns{i};
ref = get_param(blk, 'ReferenceBlock');
mask = get_param(blk, 'MaskType');
disp(['Block: ' blk]);
disp([' ReferenceBlock: ' ref]);
disp([' MaskType: ' mask]);
end
If ReferenceBlock contains simscape/ports/LConn or RConn, it’s Simscape; if it contains powerlib/Elements/LConn or similar, it’s Simulink Electrical.
This method allows you to programmatically distinguish the type and origin.
Please refer to the following documentation for more information:
Hope it helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Electrical Systems in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!