1 | function res = idSetUndParamSync(idName, attrName, attrValue, attrAbsTol) |
---|
2 | |
---|
3 | res = 0; |
---|
4 | %DServName = ''; |
---|
5 | %StandByStr = ''; %String to search in the return of "Status" command of DServer |
---|
6 | ActStatusStr = ''; |
---|
7 | attr_name_list = {''}; |
---|
8 | |
---|
9 | numLoopsWaitRes = 300; |
---|
10 | sleepTime = 3; %[s] |
---|
11 | %attrNameIsRecognized = 0; |
---|
12 | |
---|
13 | [DServName, StandByStr] = idGetUndDServer(idName); |
---|
14 | |
---|
15 | if strcmp(idName, 'HU80_TEMPO') |
---|
16 | %DServName = 'ANS-C08/EI/M-HU80.2'; %Name of Level 2 DServer |
---|
17 | %StandByStr = 'ANS-C08/EI/M-HU80.2_MotorsControl : STANDBY'; |
---|
18 | |
---|
19 | %if strcmp(attrName, 'gap') |
---|
20 | % attrNameIsRecognized = 1; |
---|
21 | %elseif strcmp(attrName, 'phase') |
---|
22 | % attrNameIsRecognized = 1; |
---|
23 | %end |
---|
24 | %if attrNameIsRecognized == 0 |
---|
25 | % fprintf('Undulator Parameter / Device Server Attribute name is not recognized\n'); |
---|
26 | % res = -1; return; |
---|
27 | %end |
---|
28 | |
---|
29 | if strcmp(attrName, 'mode') |
---|
30 | attrValue = int16(attrValue); |
---|
31 | end |
---|
32 | |
---|
33 | %Debug |
---|
34 | % attr_val_list = tango_read_attributes(DServName, attr_name_list); |
---|
35 | % if (tango_error == -1) %handle error |
---|
36 | % tango_print_error_stack; return; |
---|
37 | % end |
---|
38 | %End Debug |
---|
39 | end |
---|
40 | |
---|
41 | if strcmp(DServName, '') ~= 0 |
---|
42 | fprintf('Device Server name is not specified\n'); |
---|
43 | res = -1; return; |
---|
44 | end |
---|
45 | |
---|
46 | attr_name_val_list(1).name = attrName; attr_name_val_list(1).value = attrValue; |
---|
47 | attr_name_list = {attr_name_val_list(1).name}; |
---|
48 | |
---|
49 | tango_write_attributes(DServName, attr_name_val_list); |
---|
50 | if (tango_error == -1) %handle error |
---|
51 | tango_print_error_stack; |
---|
52 | |
---|
53 | pause(sleepTime); |
---|
54 | fprintf('Trying to repeat writing attributes after pause...\n'); |
---|
55 | tango_write_attributes(DServName, attr_name_val_list); |
---|
56 | if (tango_error == -1) %handle error |
---|
57 | tango_print_error_stack; |
---|
58 | fprintf('Failed again. Returning from the function abnormally.\n'); |
---|
59 | %res = -1; %hoping that it could still recover |
---|
60 | return; |
---|
61 | else |
---|
62 | fprintf('Succeeded writing attributes from 2nd attempt. Continuing execution of the function.\n'); |
---|
63 | end |
---|
64 | end |
---|
65 | |
---|
66 | %Waiting until the parameter is actually set |
---|
67 | for i = 1:numLoopsWaitRes |
---|
68 | attr_val_list = tango_read_attributes(DServName, attr_name_list); |
---|
69 | if (tango_error == -1) %handle error |
---|
70 | tango_print_error_stack; |
---|
71 | |
---|
72 | pause(sleepTime); |
---|
73 | fprintf('Trying to repeat reading attributes after pause...\n'); |
---|
74 | attr_val_list = tango_read_attributes(DServName, attr_name_list); |
---|
75 | if (tango_error == -1) %handle error |
---|
76 | tango_print_error_stack; |
---|
77 | fprintf('Failed again. Returning from the function abnormally.\n'); |
---|
78 | %res = -1; %hoping that it could still recover |
---|
79 | return; |
---|
80 | else |
---|
81 | fprintf('Succeeded reading attributes from 2nd attempt. Continuing execution of the function.\n'); |
---|
82 | end |
---|
83 | end |
---|
84 | |
---|
85 | valRequested = attr_name_val_list(1).value; |
---|
86 | valSet = attr_val_list(1).value(1); %check why (1) |
---|
87 | if(abs(valRequested - valSet) <= attrAbsTol) |
---|
88 | |
---|
89 | if strcmp(StandByStr, '') == 0 |
---|
90 | attr_val_list_status = tango_read_attributes(DServName, {'Status'}); |
---|
91 | if (tango_error == -1) %handle error |
---|
92 | tango_print_error_stack; |
---|
93 | |
---|
94 | pause(sleepTime); |
---|
95 | fprintf('Trying to repeat reading attributes after pause...\n'); |
---|
96 | attr_val_list_status = tango_read_attributes(DServName, {'Status'}); |
---|
97 | if (tango_error == -1) %handle error |
---|
98 | tango_print_error_stack; |
---|
99 | fprintf('Failed again. Returning from the function abnormally.\n'); |
---|
100 | %res = -1; %hoping that it could still recover |
---|
101 | return; |
---|
102 | else |
---|
103 | fprintf('Succeeded reading attributes from 2nd attempt. Continuing execution of the function.\n'); |
---|
104 | end |
---|
105 | end |
---|
106 | ActStatusStr = attr_val_list_status.value; |
---|
107 | if strncmp(ActStatusStr, StandByStr, length(StandByStr)) |
---|
108 | pause(sleepTime); |
---|
109 | return; %Normal exit |
---|
110 | end |
---|
111 | else |
---|
112 | pause(sleepTime); |
---|
113 | return; %Normal exit |
---|
114 | end |
---|
115 | end |
---|
116 | pause(sleepTime); |
---|
117 | end |
---|
118 | |
---|
119 | res = -1; |
---|
120 | fprintf('Failed to set requested Undulator Parameter value\n'); |
---|