1 | function 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 | |
---|
9 | maxDelay_s = 20; %to edit |
---|
10 | testTimePeriod_s = 1; %to edit |
---|
11 | res = -1; |
---|
12 | |
---|
13 | maxNumTests = round(maxDelay_s/testTimePeriod_s); |
---|
14 | |
---|
15 | on_or_off = tango_command_inout2(idDevServ, 'State'); |
---|
16 | if(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 |
---|
29 | end |
---|
30 | |
---|
31 | attrCurrent = strcat(idDevServ, '/currentPM'); |
---|
32 | writeattribute(attrCurrent, currentToSet); |
---|
33 | actCur = 0; |
---|
34 | for 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); |
---|
41 | end |
---|
42 | |
---|
43 | if(abs(currentToSet - actCur) > currentAbsTol) |
---|
44 | res = -1; |
---|
45 | fprintf('Failed to set the requested current\n'); |
---|
46 | end |
---|
47 | |
---|