Moose/Instrument/AH2700A.pm

filter: Statementstmt 38.9% 37 / 95 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 46.1% 12 / 26 Podpod 85.7% 12 / 14 totaltotal 43.2% 61 / 141 CC 4 SCAR 10.6
CC
4
Cov
37%
get_single
12.0
get_cable
6.0
BUILD
2.0
CRAP 2.9
« Moose/DataFile/Meta.pm ↑ Summary Moose/Instrument/SCPIBlock.pm »
1 package Lab::Moose::Instrument::AH2700A;
2 1 $Lab::Moose::Instrument::AH2700A::VERSION = '3.931';
3 #ABSTRACT: Andeen-Hagerling AH2700A ultra-precision capacitance bridge
4  
5 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Time::HiRes qw (usleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Moose::Util::TypeConstraints qw/enum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Lab::Moose::Instrument qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
13 validated_getter
14 validated_setter
15 validated_no_param_setter
16 setter_params
17 1 /;
18 1 ▶use Lab::Moose::Instrument::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Time::HiRes qw/time usleep/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Lab::Moose 'linspace';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 extends 'Lab::Moose::Instrument';
25  
26  
27 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my $self = shift;
29 # $self->get_id();
30 }
31  
32  
33 0 ▶sub set_frq {
Subroutine set_frq: not called CC=1 SCAR=6.9
Pod documented
34 0 my ( $self, $value, %args ) = validated_setter( \@_,
35 value => { isa => enum( [ ( 50..20000 ) ] ) },
36 );
37  
38 0 $self->write( command => sprintf("FREQ %d", $value), %args );
39 }
40  
41  
42 0 ▶sub get_frq {
Subroutine get_frq: not called CC=1 SCAR=6.9
Pod documented
43 0 my $self = shift;
44  
45 0 my $result = $self->query( command => sprintf("SH FR") );
46  
47 0 $result =~ /(\D+)(\d+\.\d+)(\D+)/;
48  
49 0 return $2;
50 }
51  
52  
53 0 ▶sub set_aver {
Subroutine set_aver: not called CC=1 SCAR=6.9
Pod documented
54 0 my ( $self, $value, %args ) = validated_setter( \@_,
55 value => { isa => enum( [ ( 0..15 ) ] ) },
56 );
57  
58 0 $self->write( command => sprintf( "AV %d", $value ), %args );
59 }
60  
61  
62 0 ▶sub get_aver {
Subroutine get_aver: not called CC=1 SCAR=6.9
Pod documented
63 0 my $self = shift;
64  
65 0 my $result = $self->query( command => sprintf("SH AV") );
66  
67 0 $result =~ /(\D+)(\D+\=)(\d+)/;
68  
69 0 return $3;
70 }
71  
72  
73 0 ▶sub set_bias {
Subroutine set_bias: not called CC=1 SCAR=6.9
Pod documented
74 0 my ( $self, $value, %args ) = validated_setter( \@_,
75 value => { isa => enum([qw/ OFF IHIGH ILOW /]) },
76 );
77
78 0 $self->write( command => sprintf( "BI %s", $value ), %args );
79 }
80  
81  
82 0 ▶sub get_bias {
Subroutine get_bias: not called CC=1 SCAR=6.9
Pod documented
83 0 my $self = shift;
84  
85 0 my $result = $self->query( command => sprintf("SH BI") );
86  
87 0 $result =~ /(\D+\s)(\D+)/;
88  
89 0 return $result;
90 }
91  
92  
93 0 ▶sub set_cable {
Subroutine set_cable: not called CC=1 SCAR=6.9
Pod documented
94 0 my ( $self, $cab1, $cab2, %args ) = validated_setter( \@_,
95 cab1 => { isa => enum([qw/ L RES I C /]) },
96 cab2 => { isa => 'Str' },
97 );
98  
99 0 $self->write( command => sprintf( "CAB %s %d", $cab1, $cab2 ), %args );
100 }
101  
102  
103 0 ▶sub get_cable {
Subroutine get_cable: not called CC=2 SCAR=17.9
Pod documented
104 0 my $self = shift;
105  
106 0 my $result = $self->write( command => sprintf("SH CAB") );
107  
108 0 my @results;
109  
110 0 ▶ for ( my $i = 0; $i < 4; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 4) 0 0 0
111 0 my $result = $self->read();
112 0 push( @results, $result );
113 }
114  
115 0 print " @results ";
116  
117 0 return @results;
118 }
119  
120 # used internally for get_value
121 0 ▶sub get_single {
Subroutine get_single: not called CC=3 SCAR=24.8
Pod undocumented
122 0 my ( $self, %args ) = validated_getter( \@_,
123 );
124  
125 # Implement cache; just use Lab::Moose::Instrument::Cache
126 # and write cache id => (getter => 'get_id') for all get
127 # functions?
128 0 my $average = $self->get_aver();
129 0 my $frequency = $self->get_frq();
130  
131 # Rewrite with hash
132 0 my $time_table_highf = {
133 0 => [ 0.28, 80 ],
134 1 => [ 0.29, 110 ],
135 2 => [ 0.30, 150 ],
136 3 => [ 0.33, 200 ],
137 4 => [ 0.37, 260 ],
138 5 => [ 0.44, 350 ],
139 6 => [ 0.58, 520 ],
140 7 => [ 3.2, 3200 ],
141 8 => [ 4.8, 5200 ],
142 9 => [ 7.2, 8800 ],
143 10 => [ 12.0, 16000 ],
144 11 => [ 20.0, 28000 ],
145 12 => [ 36.0, 56000 ],
146 13 => [ 68.0, 108000 ],
147 14 => [ 140.0, 220000 ],
148 15 => [ 280.0, 480000 ],
149 };
150  
151 0 my $timeout = @{ $time_table_highf->{$average} }[0]
152 0 + @{ $time_table_highf->{$average} }[1] / $frequency;
153  
154 0 ▶ if ( not exists($args{'timeout'}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"timeout"}) 0 0 0
155 0 $args{'timeout'} = 100;
156 }
157  
158 0 my $result = $self->query( command => sprintf("SI"), %args );
159 #print "$result";
160 # Rewrite with hash
161 #if ($result eq "") { croak "AH2700A: Low to Ground\n"; }
162 0 my $values;
163 0 ▶ while ( $result =~ /([A-Z])=\s?(-?\d+\.\d+)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result =~ /([A-Z])=\s?(-?\d+\.\d+)/gu) 0 0 0
164 0 $values->{$1} = $2;
165 }
166 0 $values->{E} = 00;
167 # Didn't work in my last test
168 #if ( $result =~ /^(\d+)/ and $result != /00/ ) {
169 # $values->{E} = $1;
170 #}
171
172 # TODO
173 # S was always empty in my last test and caused the script
174 # to crash, so i'll just document the first three values
175 # for the moment.
176 return (
177 $values->{C} * 1e-12,
178 $values->{L} * 1e-9,
179 $values->{V}
180 #,$values->{S}, $values->{E}
181 0 );
182 }
183  
184  
185 0 ▶sub get_value {
Subroutine get_value: not called CC=1 SCAR=6.9
Pod documented
186 0 my $self = shift;
187  
188 0 return $self->get_single(@_);
189 }
190  
191 0 ▶sub set_wait {
Subroutine set_wait: not called CC=1 SCAR=6.9
Pod documented
192 0 my ( $self, $wait, %args )
193 = validated_setter( \@_, wait => { isa => 'Num' }, );
194  
195 0 $self->write( command => sprintf( "WAIT DELAY %d", $wait ), %args );
196 }
197  
198  
199 # controls which fields are sent to GPIB port
200 0 ▶sub set_field {
Subroutine set_field: not called CC=1 SCAR=6.9
Pod documented
201 0 my ( $self, %args ) = validated_getter( \@_,
202 fi1 => { isa => 'Str' },
203 fi2 => { isa => 'Str' },
204 fi3 => { isa => 'Num' },
205 fi4 => { isa => 'Num' },
206 fi5 => { isa => 'Str' },
207 fi6 => { isa => 'Str' },
208 );
209
210 0 my $fi1 = delete $args{fi1};
211 0 my $fi2 = delete $args{fi2};
212 0 my $fi3 = delete $args{fi3};
213 0 my $fi4 = delete $args{fi4};
214 0 my $fi5 = delete $args{fi5};
215 0 my $fi6 = delete $args{fi6};
216  
217 0 $self->write( command =>
218 sprintf(
219 "FIELD %s,%s,%d,%d,%s,%s", $fi1, $fi2, $fi3, $fi4, $fi5, $fi6
220 ), %args
221 );
222 }
223  
224  
225 0 ▶sub set_volt {
Subroutine set_volt: not called CC=1 SCAR=6.9
Pod documented
226 0 my ( $self, $value, %args ) = validated_setter( \@_,
227 value => { isa => 'Num' },
228 );
229  
230 0 $self->write( command => sprintf( "V %2.2f", $value ), %args );
231 }
232  
233 __END__
« Moose/DataFile/Meta.pm ↑ Summary Moose/Instrument/SCPIBlock.pm »