forked from Modi1987/KST-Kuka-Sunrise-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcn_getIP.m
103 lines (90 loc) · 1.87 KB
/
fcn_getIP.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function [ip,errorflag]=fcn_getIP()
%% About:
% Get IP from text boxes
%% Return values:
% ip: string, ip of the robot
% errorFlag: a boolean equals to true, if the values intered in the
% textboxes are valid IP, false otherwise.
% Initiate the return values
ip=[];
errorflag=true;
ip_temp=[];
% first ip section
h=findobj(0, 'tag', 'txt_ip1');
x = get(h,'String');
disp(x)
if iserror(x)
return;
end
ip_temp=[ip_temp,x,'.'];
% second ip section
h=findobj(0, 'tag', 'txt_ip2');
x = get(h,'String');
disp(x)
if iserror(x)
return;
end
ip_temp=[ip_temp,x,'.'];
% third ip section
h=findobj(0, 'tag', 'txt_ip3');
x = get(h,'String');
disp(x)
if iserror(x)
return;
end
ip_temp=[ip_temp,x,'.'];
% fourth ip section
h=findobj(0, 'tag', 'txt_ip4');
x = get(h,'String');
disp(x)
if iserror(x)
return;
end
ip_temp=[ip_temp,x];
% if previous passed, assign return values
ip=ip_temp;
errorflag=false;
end
function flag=iserror(str)
% Initiate the return value
flag=true;
% Check if input is correct size
if isempty(str)
message='one of IP fields is empty';
showErrorPopup(message)
return;
end
if size(str,1)==1
else
message='IP is not valid';
showErrorPopup(message)
return;
end
if size(str,2)>3
message='IP is not valid';
showErrorPopup(message)
return;
end
string_of_allwable_Numeric_Values='0123456789';
n=max(max(size(str)));
for i=1:n
if sum(sum(size(strfind(string_of_allwable_Numeric_Values,str(i)))))==0
message='IP shall contain only numbers';
showErrorPopup(message)
return;
end
end
if str2num(str)>255
message='each segmnt of the IP shall be between 0 up to 255';
showErrorPopup(message)
return;
end
% If identification passed, return false, i.e no error detected
flag=false;
end
function showErrorPopup(message)
% disp(message)
ed = errordlg(message);
set(ed, 'WindowStyle', 'modal');
uiwait(ed);
end