create bus with same signal-names as output port names

1 次查看(过去 30 天)
Hello,
is there a quick way to have a bus inherit the signalnames form the output ports of a subsystem?
I am using vehicle network toolbox. CAN unpack is handy but gives a lot of signals. Now I am manually naming the signals when I create a new bus at CAN_unpack out. Any quick magic spell to speed this up?
Thanks

回答(1 个)

Simon Ellwanger
Simon Ellwanger 2021-1-19
Found a solution:
Use a blank simulink model. Copy/Past your "CAN-unpack" subsystem into it. Run the script.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% please mark the "CAN-unpack" before execution !
file=get_param(gcb,'CANdbFile'); % your CAN DBC file here!
db=canDatabase(file);
msg_name=get_param(gcb,'MsgName');
Msg=messageInfo(db,msg_name);
porthandles = get(gcbh,'PortHandles');
%%%% iterate thru all outports of the selected block and draw a signal line
for i = 1: size(porthandles.Outport,2)
%% draw a line at each Out-Port
pos = get(porthandles.Outport(i), 'Position');
linepos = [pos(1)+200 pos(2)-5 pos(1)+200+10 pos(2)+5];
temp_block = add_block('simulink/Commonly Used Blocks/Terminator',[gcs '/Term_' int2str(i)],'Position', linepos);
h1 = get_param(temp_block,'PortHandles');
add_line(gcs,porthandles.Outport(i),h1.Inport);
% get(porthandles.Outport(i)) % to see all properties
name =get(porthandles.Outport(i), 'PropagatedSignals');
linehandle = get(porthandles.Outport(i), 'Line');
set(linehandle, 'Name', name);
end
%%%% name all the signal lines according to outport-names
for i = 1: size(Msg.Signals,1)
linehandle = get(porthandles.Outport(i), 'Line');
set(linehandle, 'Name', Msg.Signals{i});
end

类别

Help CenterFile Exchange 中查找有关 Schedule Model Components 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by