Instrument/Cryogenic_SMS.pm untested

filter: Statementstmt 0.0% 0 / 117 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 153 CC 7 SCAR 19.9
CC
7
Cov
0%
ramp_to_mid
12.0
ramp_to_zero
12.0
ramp_to_max
12.0
CRAP 7.3
1 package Lab::Instrument::Cryogenic_SMS;
2 #ABSTRACT: Cryogenic SMS magnet power supply
3 $Lab::Instrument::Cryogenic_SMS::VERSION = '3.899';
4 use v5.20;
5  
6 use strict;
7 use Lab::Instrument;
8  
9 our @ISA = ('Lab::Instrument');
10  
11 # does not use any magnet supply specific code yet
12  
13 our %fields = (
14 supported_connections => [ 'GPIB', 'VISA' ],
15  
16 # default settings for the supported connections
17 connection_settings => {
18 gpib_board => 0,
19 gpib_address => undef,
20 },
21  
22 # device_settings => {
23 # use_persistentmode => 0,
24 # can_reverse => 0,
25 # can_use_negative_current => 0,
26 # },
27 );
28  
29 sub new {
30 my $proto = shift;
31 my $class = ref($proto) || $proto;
32 my $self = $class->SUPER::new(@_);
33 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
34 print "Cryogenic SMS magnet supply code is experimental.\n";
35 return $self;
36 }
37  
38 sub ramp_to_mid {
39 my $self = shift;
40 $self->write("RAMP MID\n");
41 my $status = $self->status();
42 while ( $status =~ /HOLDING/ )
43 { # takes care that command is finally executed
44 $status = $self->status();
45  
46 $status =~ /MID SETTING: (.*) AMPS/;
47 my $mid = $1;
48 $status =~ /OUTPUT: (.*) AMPS/;
49 my $out = $1;
50  
51 last if $mid == $out; # breaks if we have already reached target
52  
53 $self->write("RAMP MID\n");
54 print "power supply not responding, send command again\n";
55 sleep(1);
56 }
57  
58 while ( $status =~ /RAMPING/ ) {
59 $status = $self->status();
60 sleep(1);
61 }
62  
63 $status =~ /MID SETTING: (.*) AMPS/;
64 my $mid = $1;
65 $status =~ /OUTPUT: (.*) AMPS/;
66 my $out = $1;
67  
68 return 0 if $mid == $out;
69 return 1;
70 }
71  
72 sub ramp_to_zero {
73 my $self = shift;
74 $self->write("RAMP ZERO\n");
75 my $status = $self->status();
76 while ( $status =~ /HOLDING/ )
77 { # takes care that command is finally executed
78 $status = $self->status();
79  
80 $status =~ /OUTPUT: (.*) AMPS/;
81 my $out = $1;
82  
83 last if $out == 0; # breaks if we have already reached target
84  
85 $self->write("RAMP ZERO\n");
86 print "power supply not responding, send command again\n";
87 sleep(1);
88 }
89  
90 while ( $status =~ /RAMPING/ ) {
91 $status = $self->status();
92 sleep(1);
93 }
94  
95 $status = $self->status();
96 $status =~ /OUTPUT: (.*) AMPS/;
97 my $out = $1;
98 if ( $out == 0 ) {
99 return 0;
100 }
101 return 1;
102 }
103  
104 sub ramp_to_max {
105 my $self = shift;
106 $self->write("RAMP MAX\n");
107 my $status = $self->status();
108 while ( $status =~ /HOLDING/ )
109 { # takes care that command is finally executed
110 $status = $self->status();
111  
112 $status =~ /MAX SETTING: (.*) AMPS/;
113 my $max = $1;
114 $status =~ /OUTPUT: (.*) AMPS/;
115 my $out = $1;
116  
117 last if $max == $out; # breaks if we have already reached target
118  
119 $self->write("RAMP MID\n");
120 print "power supply not responding, send command again\n";
121 sleep(1);
122 }
123  
124 while ( $status =~ /RAMPING/ ) {
125 $status = $self->status();
126 sleep(1);
127 }
128  
129 $status =~ /MAX SETTING: (.*) AMPS/;
130 my $max = $1;
131 $status =~ /OUTPUT: (.*) AMPS/;
132 my $out = $1;
133  
134 return 0 if $max == $out;
135 return 1;
136 }
137  
138 sub heater_on {
139 my $self = shift;
140 $self->write("HEATER ON\n");
141  
142 my $status = $self->status();
143 while ( $status =~ /HEATER STATUS: OFF/ )
144 { # takes care that command is finally executed
145 sleep(1);
146 $self->write("HEATER ON\n");
147 print "power supply not responding, send command again\n";
148 sleep(1);
149 $status = $self->status();
150 }
151 sleep(10);
152 return 0;
153 }
154  
155 sub heater_off {
156 my $self = shift;
157 $self->write("HEATER OFF\n");
158  
159 my $status = $self->status();
160 while ( $status =~ /HEATER STATUS: ON/ )
161 { # takes care that command is finally executed
162 sleep(1);
163 print "power supply not responding, send command again\n";
164 $self->write("HEATER OFF\n");
165 sleep(1);
166 $status = $self->status();
167 }
168 sleep(10);
169 return 0;
170 }
171  
172 sub status {
173 my $self = shift;
174 my $result = $self->query( command => "U\n", read_length => 1000 );
175 for ( my $i = 1; $i <= 20; $i++ ) {
176 $result .= $self->query( command => "U\n", read_length => 1000 );
177  
178 }
179 return $result;
180 }
181  
182 sub read_messages {
183 my $self = shift;
184 my $result = $self->read( read_length => 1000 );
185 }
186  
187 1;
188  
189 __END__