Instrument/AH2700A.pm untested

filter: Statementstmt 0.0% 0 / 190 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 0.0% 0 / 36 Podpod 0.0% 0 / 32 totaltotal 0.0% 0 / 338 CC 15 SCAR 22.2
CC
15
Cov
0%
set_bright
42.0
get_single
20.0
set_frq
6.0
CRAP 9.2
1 package Lab::Instrument::AH2700A;
2 #ABSTRACT: Andeen-Hagerling AH2700A ultra-precision capacitance bridge
3 $Lab::Instrument::AH2700A::VERSION = '3.899';
4 use v5.20;
5  
6 use strict;
7 use Time::HiRes qw (usleep);
8 use Lab::Instrument;
9  
10 our @ISA = ("Lab::Instrument");
11  
12 our %fields = (
13 supported_connections => [ 'VISA_GPIB', 'GPIB', 'DEBUG', 'DUMMY' ],
14  
15 # default settings for the supported connections
16 connection_settings => {
17 gpib_board => 0,
18 gpib_address => undef,
19 timeout => 2,
20 termchar => "\n"
21 },
22  
23 device_settings => {
24  
25 },
26  
27 device_cache => {
28 aver => undef,
29 frq => undef,
30 bias => undef
31 },
32  
33 device_cache_order => [],
34  
35 );
36  
37 sub new {
38 my $proto = shift;
39 my $class = ref($proto) || $proto;
40 my $self = $class->SUPER::new(@_);
41 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
42  
43 return $self;
44 }
45  
46 sub _device_init {
47  
48 }
49  
50 sub set_frq {
51 my $self = shift;
52  
53 # read from cache or from device?
54 my ( $frq, $tail ) = $self->_check_args( \@_, ['frq'] );
55  
56 if ( $frq < 50 or $frq > 20000 ) {
57 Lab::Exception::CorruptParameter->throw(
58 error => "bad frequency-parameter!\n" );
59 }
60 else {
61 $self->write( sprintf( "FREQ %d", $frq ), $tail );
62 }
63  
64 }
65  
66 sub get_frq {
67 my $self = shift;
68  
69 my $result = $self->query( sprintf("SH FR") );
70  
71 $result =~ /(\D+)(\d+\.\d+)(\D+)/;
72  
73 return $2;
74  
75 }
76  
77 sub set_aver {
78 my $self = shift;
79  
80 # read from cache or from device?
81 my ( $aver, $tail ) = $self->_check_args( \@_, ['aver'] );
82  
83 if ( $aver < 0 or $aver > 15 ) {
84 Lab::Exception::CorruptParameter->throw(
85 error => "bad average-parameter!\n" );
86 }
87 else {
88 $self->write( sprintf( "AV %d", $aver ), $tail );
89 }
90 }
91  
92 sub get_aver {
93 my $self = shift;
94  
95 my $result = $self->query( sprintf("SH AV") );
96  
97 $result =~ /(\D+)(\D+\=)(\d+)/;
98  
99 return $3;
100  
101 }
102  
103 sub set_bias {
104 my $self = shift;
105  
106 # read from cache or from device?
107 my ( $bias, $tail ) = $self->_check_args( \@_, ['bias'] );
108  
109 if ( $bias eq "OFF" or $bias eq "IHIGH" or $bias eq "ILOW" ) {
110 $self->write( sprintf( "BI %s", $bias ), $tail );
111 }
112 else {
113 Lab::Exception::CorruptParameter->throw(
114 error => "bad bias-parameter!\n" );
115 }
116  
117 }
118  
119 sub get_bias {
120 my $self = shift;
121  
122 my $result = $self->query( sprintf("SH BI") );
123  
124 $result =~ /(\D+\s)(\D+)/;
125  
126 return $2;
127  
128 }
129  
130 sub set_bright {
131 my $self = shift;
132  
133 # read from cache or from device?
134 my ( $bright1, $bright2, $tail )
135 = $self->_check_args( \@_, [ 'bright1', 'bright2' ] );
136  
137 if (
138 (
139 $bright1 ne 'ALL'
140 or $bright1 ne 'C'
141 or $bright1 ne 'LOS'
142 or $bright1 ne 'OT'
143 )
144 and ( $bright2 < 0 or $bright2 > 9 )
145 ) {
146 Lab::Exception::CorruptParameter->throw(
147 error => "bad brightness-parameter!\n" );
148 }
149 if ( $bright1 eq 'ALL' ) {
150 $self->write( sprintf( "BR %s %d", $bright1, $bright2 ), $tail );
151 }
152 if ( $bright1 eq 'C' ) {
153 $self->write( sprintf( "BR %s %d", $bright1, $bright2 ), $tail );
154 }
155 if ( $bright1 eq 'LOS' ) {
156 $self->write( sprintf( "BR %s %d", $bright1, $bright2 ), $tail );
157 }
158 if ( $bright1 eq 'OT' ) {
159 $self->write( sprintf( "BR %s %d", $bright1, $bright2 ), $tail );
160 }
161  
162 }
163  
164 sub get_bright {
165 my $self = shift;
166  
167 my $result = $self->query( sprintf("SH BR") );
168  
169 $result =~ /(\D+\s)(\D\=\d\s\D\=\d\s\D\=\d)/;
170  
171 return $2;
172  
173 }
174  
175 sub set_cable {
176 my $self = shift;
177  
178 # read from cache or from device?
179 my ( $cab1, $cab2, $tail )
180 = $self->_check_args( \@_, [ 'cab1', 'cab2' ] );
181  
182 if ( not $cab1 =~ m/L|RES|I|C/ ) {
183 Lab::Exception::CorruptParameter->throw(
184 error => "bad cable-parameter!\n" );
185 }
186 else {
187 $self->write( sprintf( "CAB %s %d", $cab1, $cab2 ), $tail );
188 }
189  
190 }
191  
192 sub get_cable {
193 my $self = shift;
194  
195 my $result = $self->write( sprintf("SH CAB") );
196  
197 my @results;
198  
199 for ( my $i = 0; $i < 4; $i++ ) {
200 my $result = $self->read();
201 push( @results, $result );
202 }
203  
204 print " @results ";
205  
206 return @results;
207  
208 }
209  
210 # set number of measurements for continuous-mode
211 sub set_cont {
212 my $self = shift;
213  
214 # read from cache or from device?
215 my ( $cont, $tail ) = $self->_check_args( \@_, ['cont'] );
216  
217 if ( $cont > 10 ) {
218 Lab::Exception::CorruptParameter->throw(
219 error => "number of measurements higher than 10!\n" );
220 }
221 else {
222 $self->write( sprintf( "CO TO %d", $cont ), $tail );
223 }
224 }
225  
226 # get number of measurements for continuous-mode
227 sub get_cont {
228 my $self = shift;
229  
230 my $result = $self->query( sprintf("SH CO TO") );
231  
232 $result =~ /(\D+)(\D+\=)(\d+)/;
233  
234 return $result;
235  
236 }
237  
238 # start continuous-mode
239 sub cont {
240 my $self = shift;
241  
242 $self->write("CO");
243  
244 }
245  
246 sub get_single {
247 my $self = shift;
248  
249 # read from cache or from device?
250 my ($tail) = $self->_check_args( \@_ );
251  
252 my $average = $self->get_aver( { read_mode => "cache" } );
253 my $frequency = $self->get_frq( { read_mode => "cache" } );
254  
255 my $time_table_highf = {
256 0 => [ 0.28, 80 ],
257 1 => [ 0.29, 110 ],
258 2 => [ 0.30, 150 ],
259 3 => [ 0.33, 200 ],
260 4 => [ 0.37, 260 ],
261 5 => [ 0.44, 350 ],
262 6 => [ 0.58, 520 ],
263 7 => [ 3.2, 3200 ],
264 8 => [ 4.8, 5200 ],
265 9 => [ 7.2, 8800 ],
266 10 => [ 12.0, 16000 ],
267 11 => [ 20.0, 28000 ],
268 12 => [ 36.0, 56000 ],
269 13 => [ 68.0, 108000 ],
270 14 => [ 140.0, 220000 ],
271 15 => [ 280.0, 480000 ],
272  
273 };
274  
275 my $timeout = @{ $time_table_highf->{$average} }[0]
276 + @{ $time_table_highf->{$average} }[1] / $frequency;
277  
278 if ( not defined $tail->{timeout} ) {
279 $tail->{timeout} = 100;
280 }
281  
282 my $result = $self->request( sprintf("SI"), $tail );
283 my $values;
284 while ( $result =~ /([A-Z])=\s(\d+\.\d+)/g ) {
285 $values->{$1} = $2;
286 }
287 $values->{E} = 00;
288 if ( $result =~ /^(\d+)/ and $result != /00/ ) {
289 $values->{E} = $1;
290 print new Lab::Exception::Warning(
291 error => "Error in get_single. Errorcode = "
292 . $values->{E}
293 . "\n" );
294 }
295  
296 if ( wantarray() ) {
297 return (
298 $values->{C} * 1e-12,
299 $values->{L} * 1e-9,
300 $values->{V}, $values->{S}, $values->{E}
301 );
302 }
303 else {
304 return $values->{C} * 1e-12;
305 }
306  
307 }
308  
309 sub get_value {
310 my $self = shift;
311  
312 return $self->get_single(@_);
313 }
314  
315 sub set_wait {
316 my $self = shift;
317  
318 # read from cache or from device?
319 my ( $wait, $tail ) = $self->_check_args( \@_, ['wait'] );
320  
321 $self->write( sprintf( "WAIT DELAY %d", $wait ), $tail );
322  
323 }
324  
325 sub reset {
326 my $self = shift;
327  
328 $self->write("*RST");
329  
330 }
331  
332 # fetch-function
333 sub get_last {
334 my $self = shift;
335  
336 $self->write("FE");
337  
338 }
339  
340 # controls which fields are sent to GPIB port
341 sub set_field {
342 my $self = shift;
343  
344 # read from cache or from device?
345 my ( $fi1, $fi2, $fi3, $fi4, $fi5, $fi6, $tail ) = $self->_check_args(
346 \@_,
347 [ 'fi1', 'fi2', 'fi3', 'fi4', 'fi5', 'fi6' ]
348 );
349  
350 $self->write(
351 sprintf(
352 "FIELD %s,%s,%d,%d,%s,%s", $fi1, $fi2, $fi3, $fi4, $fi5, $fi6
353 ),
354 $tail
355 );
356  
357 }
358  
359 sub get_field {
360 my $self = shift;
361  
362 $self->write("SH FI");
363  
364 }
365  
366 sub set_gpib {
367 my $self = shift;
368  
369 # read from cache or from device?
370 my ( $gp1, $gp2, $gp3, $gp4, $gp5, $tail )
371 = $self->_check_args( \@_, [ 'gp1', 'gp2', 'gp3', 'gp4', 'gp5' ] );
372  
373 $self->write(
374 sprintf( "GP %d,%d,%s,%s,%s", $gp1, $gp2, $gp3, $gp4, $gp5 ),
375 $tail
376 );
377  
378 }
379  
380 sub get_gpib {
381 my $self = shift;
382  
383 $self->write("SH GP");
384  
385 }
386  
387 # stops remote mode (switches to local mode)
388 sub go_to_local {
389 my $self = shift;
390  
391 $self->write("LOC");
392  
393 }
394  
395 sub set_date {
396 my $self = shift;
397  
398 # read from cache or from device?
399 my ( $yr, $mo, $day, $tail )
400 = $self->_check_args( \@_, [ 'yr', 'mo', 'day' ] );
401  
402 $self->write( sprintf( "STO %d,%d,%d", $yr, $mo, $day ), $tail );
403  
404 }
405  
406 sub get_date {
407 my $self = shift;
408  
409 $self->write("SH DATE");
410  
411 }
412  
413 sub set_time {
414 my $self = shift;
415  
416 # read from cache or from device?
417 my ( $hr, $min, $sec, $tail )
418 = $self->_check_args( \@_, [ 'hr', 'min', 'sec' ] );
419  
420 $self->write( sprintf( "STO %d,%d,%d", $hr, $min, $sec ), $tail );
421  
422 }
423  
424 sub get_time {
425 my $self = shift;
426  
427 $self->write("SH TIME");
428  
429 }
430  
431 sub set_units {
432 my $self = shift;
433  
434 # read from cache or from device?
435 my ( $units, $tail ) = $self->_check_args( \@_, ['units'] );
436  
437 if ( not $units =~ m/NS|DS|KO|GO|JP/ ) {
438 Lab::Exception::CorruptParameter->throw(
439 error => "bad units-parameter!\n" );
440 }
441 else {
442 $self->write( sprintf( "UN %s", $units ), $tail );
443 }
444  
445 }
446  
447 sub set_volt {
448 my $self = shift;
449  
450 # read from cache or from device?
451 my ( $volt, $tail ) = $self->_check_args( \@_, ['volt'] );
452  
453 $self->write( sprintf( "V %2.2f", $volt ), $tail );
454  
455 }
456  
457 sub get_volt {
458 my $self = shift;
459  
460 my $result = $self->query( sprintf("SH V") );
461  
462 $result =~ /(\D+)(\d+\.\d+)(\D+)/;
463  
464 return $2;
465  
466 }
467  
468 #sub sample_select {} # only in conjunction with the sample switch port
469  
470 1;
471  
472 __END__