-
Notifications
You must be signed in to change notification settings - Fork 1
/
fulfillPorts.m
85 lines (74 loc) · 2.66 KB
/
fulfillPorts.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function handles = fulfillPorts(ports)
% FULFILLPORTS For unconnected ports, creates a Ground or Terminator block
% and connects to it with a signal line. Outports are connected to Terminators
% and Inports are connected to Grounds. Already connected ports are skipped.
%
% Inputs:
% ports Vector of port handles.
%
% Outports:
% N/A
handles = ones(size(ports)) * -1; % -1 if no terminator/ground added
for i = 1:length(ports)
% Find line if it exists
line = get_param(ports(i), 'Line');
if line ~= -1
hasLine = true;
else
hasLine = false;
end
% Get the port's system
portSys = get_param(get_param(ports(i), 'Parent'), 'Parent');
if strcmp(get_param(ports(i), 'PortType'), 'outport')
% Find line destination if it exists
if hasLine
if get_param(line,'DstPortHandle') ~= -1
hasDst = true;
else
hasDst = false;
end
else
hasDst = false;
end
if ~hasDst
% Create terminator
bHandle = add_block('built-in/Terminator', ...
[portSys '/generated_terminator'], 'MakeNameUnique', 'on');
handles(i) = bHandle;
% Get the terminator's inport
pHandles = get_param(bHandle, 'PortHandles');
inHandle = pHandles.Inport;
% Connect terminator to ports(i)
if hasLine
delete(line)
end
add_line(portSys, ports(i), inHandle);
end
else % Inport, Trigger
% Find line source if it exists
if hasLine
if get_param(line, 'SrcPortHandle') ~= -1
hasSrc = true;
else
hasSrc = false;
end
else
hasSrc = false;
end
if ~hasSrc
% Create ground
bHandle = add_block('built-in/Ground', ...
[portSys '/generated_ground'], 'MakeNameUnique', 'on');
handles(i) = bHandle;
% Get the ground's inport
pHandles = get_param(bHandle, 'PortHandles');
outHandle = pHandles.Outport;
% Connect ground to ports(i)
if hasLine
delete(line)
end
add_line(portSys, outHandle, ports(i));
end
end
end
end