source: MML/trunk/machine/SOLEIL/StorageRing/insertions/idSetCurrentSync.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: 1.3 KB
Line 
1function res = idSetCurrentSync(idDevServ, currentToSet, currentAbsTol)
2% Written by Oleg ? Set one current of a power supply, using device of
3% level 1
4% 1) Sets power supply "idServ" ON
5% 2) Sets setpoint "currentToSet" to attribute "idDevServ/currentPM"
6% 3) Waits until current is reached (depending on maxNumTests and
7% currentAbsTol)
8
9maxDelay_s = 20; %to edit
10testTimePeriod_s = 1; %to edit
11res = -1;
12
13maxNumTests = round(maxDelay_s/testTimePeriod_s);
14
15on_or_off = tango_command_inout2(idDevServ, 'State');
16if(strcmp(on_or_off, 'ON') == 0)
17    tango_command_inout2(idDevServ, 'On');
18    for i = 1:maxNumTests
19        on_or_off = tango_command_inout2(idDevServ, 'State');
20        if(strcmp(on_or_off, 'ON'))
21            break;
22        end
23        pause(testTimePeriod_s);
24    end
25    if(strcmp(on_or_off, 'ON') == 0)
26        fprintf('Failed to set the device ON');
27        return;
28    end
29end
30
31attrCurrent = strcat(idDevServ, '/currentPM');
32writeattribute(attrCurrent, currentToSet);
33actCur = 0;
34for i = 1:maxNumTests
35        actCur = readattribute([idDevServ, '/current']);
36    if(abs(currentToSet - actCur) <= currentAbsTol)
37        res = 0;
38        return;
39    end
40        pause(testTimePeriod_s);
41end
42
43if(abs(currentToSet - actCur) > currentAbsTol)
44        res = -1;
45        fprintf('Failed to set the requested current\n');
46end
47
Note: See TracBrowser for help on using the repository browser.