File Coverage

blib/lib/Lab/Instrument/AH2700A.pm
Criterion Covered Total %
statement 11 148 7.4
branch 0 28 0.0
condition 0 27 0.0
subroutine 4 36 11.1
pod 1 31 3.2
total 16 270 5.9


line stmt bran cond sub pod time code
1             package Lab::Instrument::AH2700A;
2             #ABSTRACT: Andeen-Hagerling AH2700A ultra-precision capacitance bridge
3             $Lab::Instrument::AH2700A::VERSION = '3.881';
4 1     1   2984 use v5.20;
  1         4  
5              
6 1     1   7 use strict;
  1         3  
  1         26  
7 1     1   6 use Time::HiRes qw (usleep);
  1         2  
  1         6  
8 1     1   106 use Lab::Instrument;
  1         3  
  1         2596  
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 0     0 1   my $proto = shift;
39 0   0       my $class = ref($proto) || $proto;
40 0           my $self = $class->SUPER::new(@_);
41 0           $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
  0            
42              
43 0           return $self;
44             }
45              
46       0     sub _device_init {
47              
48             }
49              
50             sub set_frq {
51 0     0 0   my $self = shift;
52              
53             # read from cache or from device?
54 0           my ( $frq, $tail ) = $self->_check_args( \@_, ['frq'] );
55              
56 0 0 0       if ( $frq < 50 or $frq > 20000 ) {
57 0           Lab::Exception::CorruptParameter->throw(
58             error => "bad frequency-parameter!\n" );
59             }
60             else {
61 0           $self->write( sprintf( "FREQ %d", $frq ), $tail );
62             }
63              
64             }
65              
66             sub get_frq {
67 0     0 0   my $self = shift;
68              
69 0           my $result = $self->query( sprintf("SH FR") );
70              
71 0           $result =~ /(\D+)(\d+\.\d+)(\D+)/;
72              
73 0           return $2;
74              
75             }
76              
77             sub set_aver {
78 0     0 0   my $self = shift;
79              
80             # read from cache or from device?
81 0           my ( $aver, $tail ) = $self->_check_args( \@_, ['aver'] );
82              
83 0 0 0       if ( $aver < 0 or $aver > 15 ) {
84 0           Lab::Exception::CorruptParameter->throw(
85             error => "bad average-parameter!\n" );
86             }
87             else {
88 0           $self->write( sprintf( "AV %d", $aver ), $tail );
89             }
90             }
91              
92             sub get_aver {
93 0     0 0   my $self = shift;
94              
95 0           my $result = $self->query( sprintf("SH AV") );
96              
97 0           $result =~ /(\D+)(\D+\=)(\d+)/;
98              
99 0           return $3;
100              
101             }
102              
103             sub set_bias {
104 0     0 0   my $self = shift;
105              
106             # read from cache or from device?
107 0           my ( $bias, $tail ) = $self->_check_args( \@_, ['bias'] );
108              
109 0 0 0       if ( $bias eq "OFF" or $bias eq "IHIGH" or $bias eq "ILOW" ) {
      0        
110 0           $self->write( sprintf( "BI %s", $bias ), $tail );
111             }
112             else {
113 0           Lab::Exception::CorruptParameter->throw(
114             error => "bad bias-parameter!\n" );
115             }
116              
117             }
118              
119             sub get_bias {
120 0     0 0   my $self = shift;
121              
122 0           my $result = $self->query( sprintf("SH BI") );
123              
124 0           $result =~ /(\D+\s)(\D+)/;
125              
126 0           return $2;
127              
128             }
129              
130             sub set_bright {
131 0     0 0   my $self = shift;
132              
133             # read from cache or from device?
134 0           my ( $bright1, $bright2, $tail )
135             = $self->_check_args( \@_, [ 'bright1', 'bright2' ] );
136              
137 0 0 0       if (
      0        
      0        
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 0           Lab::Exception::CorruptParameter->throw(
147             error => "bad brightness-parameter!\n" );
148             }
149 0 0         if ( $bright1 eq 'ALL' ) {
150 0           $self->write( sprintf( "BR %s %d", $bright1, $bright2 ), $tail );
151             }
152 0 0         if ( $bright1 eq 'C' ) {
153 0           $self->write( sprintf( "BR %s %d", $bright1, $bright2 ), $tail );
154             }
155 0 0         if ( $bright1 eq 'LOS' ) {
156 0           $self->write( sprintf( "BR %s %d", $bright1, $bright2 ), $tail );
157             }
158 0 0         if ( $bright1 eq 'OT' ) {
159 0           $self->write( sprintf( "BR %s %d", $bright1, $bright2 ), $tail );
160             }
161              
162             }
163              
164             sub get_bright {
165 0     0 0   my $self = shift;
166              
167 0           my $result = $self->query( sprintf("SH BR") );
168              
169 0           $result =~ /(\D+\s)(\D\=\d\s\D\=\d\s\D\=\d)/;
170              
171 0           return $2;
172              
173             }
174              
175             sub set_cable {
176 0     0 0   my $self = shift;
177              
178             # read from cache or from device?
179 0           my ( $cab1, $cab2, $tail )
180             = $self->_check_args( \@_, [ 'cab1', 'cab2' ] );
181              
182 0 0         if ( not $cab1 =~ m/L|RES|I|C/ ) {
183 0           Lab::Exception::CorruptParameter->throw(
184             error => "bad cable-parameter!\n" );
185             }
186             else {
187 0           $self->write( sprintf( "CAB %s %d", $cab1, $cab2 ), $tail );
188             }
189              
190             }
191              
192             sub get_cable {
193 0     0 0   my $self = shift;
194              
195 0           my $result = $self->write( sprintf("SH CAB") );
196              
197 0           my @results;
198              
199 0           for ( my $i = 0; $i < 4; $i++ ) {
200 0           my $result = $self->read();
201 0           push( @results, $result );
202             }
203              
204 0           print " @results ";
205              
206 0           return @results;
207              
208             }
209              
210             # set number of measurements for continuous-mode
211             sub set_cont {
212 0     0 0   my $self = shift;
213              
214             # read from cache or from device?
215 0           my ( $cont, $tail ) = $self->_check_args( \@_, ['cont'] );
216              
217 0 0         if ( $cont > 10 ) {
218 0           Lab::Exception::CorruptParameter->throw(
219             error => "number of measurements higher than 10!\n" );
220             }
221             else {
222 0           $self->write( sprintf( "CO TO %d", $cont ), $tail );
223             }
224             }
225              
226             # get number of measurements for continuous-mode
227             sub get_cont {
228 0     0 0   my $self = shift;
229              
230 0           my $result = $self->query( sprintf("SH CO TO") );
231              
232 0           $result =~ /(\D+)(\D+\=)(\d+)/;
233              
234 0           return $result;
235              
236             }
237              
238             # start continuous-mode
239             sub cont {
240 0     0 0   my $self = shift;
241              
242 0           $self->write("CO");
243              
244             }
245              
246             sub get_single {
247 0     0 0   my $self = shift;
248              
249             # read from cache or from device?
250 0           my ($tail) = $self->_check_args( \@_ );
251              
252 0           my $average = $self->get_aver( { read_mode => "cache" } );
253 0           my $frequency = $self->get_frq( { read_mode => "cache" } );
254              
255 0           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 0           my $timeout = @{ $time_table_highf->{$average} }[0]
276 0           + @{ $time_table_highf->{$average} }[1] / $frequency;
  0            
277              
278 0 0         if ( not defined $tail->{timeout} ) {
279 0           $tail->{timeout} = 100;
280             }
281              
282 0           my $result = $self->request( sprintf("SI"), $tail );
283 0           my $values;
284 0           while ( $result =~ /([A-Z])=\s(\d+\.\d+)/g ) {
285 0           $values->{$1} = $2;
286             }
287 0           $values->{E} = 00;
288 0 0 0       if ( $result =~ /^(\d+)/ and $result != /00/ ) {
289 0           $values->{E} = $1;
290             print new Lab::Exception::Warning(
291             error => "Error in get_single. Errorcode = "
292             . $values->{E}
293 0           . "\n" );
294             }
295              
296 0 0         if ( wantarray() ) {
297             return (
298             $values->{C} * 1e-12,
299             $values->{L} * 1e-9,
300             $values->{V}, $values->{S}, $values->{E}
301 0           );
302             }
303             else {
304 0           return $values->{C} * 1e-12;
305             }
306              
307             }
308              
309             sub get_value {
310 0     0 0   my $self = shift;
311              
312 0           return $self->get_single(@_);
313             }
314              
315             sub set_wait {
316 0     0 0   my $self = shift;
317              
318             # read from cache or from device?
319 0           my ( $wait, $tail ) = $self->_check_args( \@_, ['wait'] );
320              
321 0           $self->write( sprintf( "WAIT DELAY %d", $wait ), $tail );
322              
323             }
324              
325             sub reset {
326 0     0 0   my $self = shift;
327              
328 0           $self->write("*RST");
329              
330             }
331              
332             # fetch-function
333             sub get_last {
334 0     0 0   my $self = shift;
335              
336 0           $self->write("FE");
337              
338             }
339              
340             # controls which fields are sent to GPIB port
341             sub set_field {
342 0     0 0   my $self = shift;
343              
344             # read from cache or from device?
345 0           my ( $fi1, $fi2, $fi3, $fi4, $fi5, $fi6, $tail ) = $self->_check_args(
346             \@_,
347             [ 'fi1', 'fi2', 'fi3', 'fi4', 'fi5', 'fi6' ]
348             );
349              
350 0           $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 0     0 0   my $self = shift;
361              
362 0           $self->write("SH FI");
363              
364             }
365              
366             sub set_gpib {
367 0     0 0   my $self = shift;
368              
369             # read from cache or from device?
370 0           my ( $gp1, $gp2, $gp3, $gp4, $gp5, $tail )
371             = $self->_check_args( \@_, [ 'gp1', 'gp2', 'gp3', 'gp4', 'gp5' ] );
372              
373 0           $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 0     0 0   my $self = shift;
382              
383 0           $self->write("SH GP");
384              
385             }
386              
387             # stops remote mode (switches to local mode)
388             sub go_to_local {
389 0     0 0   my $self = shift;
390              
391 0           $self->write("LOC");
392              
393             }
394              
395             sub set_date {
396 0     0 0   my $self = shift;
397              
398             # read from cache or from device?
399 0           my ( $yr, $mo, $day, $tail )
400             = $self->_check_args( \@_, [ 'yr', 'mo', 'day' ] );
401              
402 0           $self->write( sprintf( "STO %d,%d,%d", $yr, $mo, $day ), $tail );
403              
404             }
405              
406             sub get_date {
407 0     0 0   my $self = shift;
408              
409 0           $self->write("SH DATE");
410              
411             }
412              
413             sub set_time {
414 0     0 0   my $self = shift;
415              
416             # read from cache or from device?
417 0           my ( $hr, $min, $sec, $tail )
418             = $self->_check_args( \@_, [ 'hr', 'min', 'sec' ] );
419              
420 0           $self->write( sprintf( "STO %d,%d,%d", $hr, $min, $sec ), $tail );
421              
422             }
423              
424             sub get_time {
425 0     0 0   my $self = shift;
426              
427 0           $self->write("SH TIME");
428              
429             }
430              
431             sub set_units {
432 0     0 0   my $self = shift;
433              
434             # read from cache or from device?
435 0           my ( $units, $tail ) = $self->_check_args( \@_, ['units'] );
436              
437 0 0         if ( not $units =~ m/NS|DS|KO|GO|JP/ ) {
438 0           Lab::Exception::CorruptParameter->throw(
439             error => "bad units-parameter!\n" );
440             }
441             else {
442 0           $self->write( sprintf( "UN %s", $units ), $tail );
443             }
444              
445             }
446              
447             sub set_volt {
448 0     0 0   my $self = shift;
449              
450             # read from cache or from device?
451 0           my ( $volt, $tail ) = $self->_check_args( \@_, ['volt'] );
452              
453 0           $self->write( sprintf( "V %2.2f", $volt ), $tail );
454              
455             }
456              
457             sub get_volt {
458 0     0 0   my $self = shift;
459              
460 0           my $result = $self->query( sprintf("SH V") );
461              
462 0           $result =~ /(\D+)(\d+\.\d+)(\D+)/;
463              
464 0           return $2;
465              
466             }
467              
468             #sub sample_select {} # only in conjunction with the sample switch port
469              
470             1;
471              
472             __END__
473              
474             =pod
475              
476             =encoding UTF-8
477              
478             =head1 NAME
479              
480             Lab::Instrument::AH2700A - Andeen-Hagerling AH2700A ultra-precision capacitance bridge
481              
482             =head1 VERSION
483              
484             version 3.881
485              
486             =head1 COPYRIGHT AND LICENSE
487              
488             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
489              
490             Copyright 2013 Christian Butschkow
491             2016 Andreas K. Huettel, Simon Reinhardt
492             2017 Andreas K. Huettel
493             2020 Andreas K. Huettel
494              
495              
496             This is free software; you can redistribute it and/or modify it under
497             the same terms as the Perl 5 programming language system itself.
498              
499             =cut