source: MML/trunk/machine/SOLEIL/StorageRing/insertions/IDStarter/idSetUndParamSync.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 4.1 KB
Line 
1function res = idSetUndParamSync(idName, attrName, attrValue, attrAbsTol)
2
3res = 0;
4%DServName = '';
5%StandByStr = ''; %String to search in the return of "Status" command of DServer
6ActStatusStr = '';
7attr_name_list = {''};
8
9numLoopsWaitRes = 300;
10sleepTime = 3; %[s]
11%attrNameIsRecognized = 0;
12
13[DServName, StandByStr] = idGetUndDServer(idName);
14
15if 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
39end
40
41if strcmp(DServName, '') ~= 0
42    fprintf('Device Server name is not specified\n');
43    res = -1; return;
44end
45
46attr_name_val_list(1).name = attrName; attr_name_val_list(1).value = attrValue;
47attr_name_list = {attr_name_val_list(1).name};
48
49tango_write_attributes(DServName, attr_name_val_list);
50if (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
64end
65
66%Waiting until the parameter is actually set
67for 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);
117end
118
119res = -1;
120fprintf('Failed to set requested Undulator Parameter value\n');
Note: See TracBrowser for help on using the repository browser.