create bus with same signal-names as output port names

1 Ansicht (letzte 30 Tage)
Simon Ellwanger
Simon Ellwanger am 25 Jun. 2020
Bearbeitet: Simon Ellwanger am 19 Jan. 2021
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

Antworten (1)

Simon Ellwanger
Simon Ellwanger am 19 Jan. 2021
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

Kategorien

Mehr zu Schedule Model Components finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by