Instrument/HP3458A.pm

filter: Statementstmt 11.0% 24 / 217 Branchbran 0.0% 0 / 104 Conditioncond 0.0% 0 / 68 MC/DCmcdc 0.0% 0 / 38 Subroutinesub 20.5% 7 / 34 Podpod 73.0% 19 / 26 totaltotal 10.2% 50 / 487 SCAR 85.1
CC
77
Cov
6%
configure_voltage_dc_trigger_highspeed
552.0
configure_voltage_dc
210.0
configure_voltage_dc_trigger
72.0
CRAP 4974.9
« Instrument/Keithley2000.pm ↑ Summary Bus/USBtmc.pm »
1 package Lab::Instrument::HP3458A;
2 #ABSTRACT: Agilent 3458A Multimeter
3 1 $Lab::Instrument::HP3458A::VERSION = '3.881';
4 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Lab::Instrument;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Lab::Instrument::Multimeter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Time::HiRes qw (usleep sleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our @ISA = ("Lab::Instrument::Multimeter");
12  
13 1 our %fields = (
14 supported_connections => ['GPIB'],
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 pl_freq => 50,
24 },
25  
26 device_cache => {
27 autozero => undef,
28 },
29  
30 );
31  
32 sub new {
33 0 ▶ my $proto = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
34 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
35 0 my $self = $class->SUPER::new(@_);
36 0 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
37  
38 0 return $self;
39 }
40  
41 sub _device_init {
42 0 ▶ my $self = shift;
Subroutine _device_init: not called CC=1 SCAR=6.9
43  
44 #$self->connection()->SetTermChar("\r\n");
45 #$self->connection()->EnableTermChar(1);
46 #print "hallo\n";
47 0 $self->write( "END 2", error_check => 1 )
48 ; # or ERRSTR? and other queries will time out, unless using a line/message end character
49 0 $self->write( 'TARM AUTO', error_check => 1 ); # keep measuring
50 0 $self->write( 'TRIG AUTO', error_check => 1 ); # keep measuring
51 0 $self->write( 'NRDGS 1,AUTO', error_check => 1 ); # keep measuring
52 }
53  
54 #
55 # utility methods
56 #
57  
58 sub configure_voltage_dc {
59 0 ▶ my $self = shift;
Subroutine configure_voltage_dc: not called CC=14 SCAR=53.5
Pod documented
60  
61 0 my ( $range, $tint ) = $self->_check_args( \@_, [ 'range', 'tint' ] );
62  
63 0 my $range_cmd = "FUNC DCV ";
64  
65 0 ▶ if ( $range eq 'AUTO' || !defined($range) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($range eq 'AUTO' or not defined $range) { } 0 0 0
elsif ($range =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u) { } 0 0 0
elsif (not $range =~ /^(MIN|MAX)$/u) { } 0 0 0
Condition0%0/3
$range eq "AUTO" or not defined $range
l!l&&r!l&&!r
000
MC/DC0%0/2
$range eq "AUTO" or not defined $range
$range eq "AUTO" not defined $range
Truth table0%0/3
A or not(B)
A= $range eq "AUTO"B= not defined $range
ABresult
1X1
011
000
66 0 $range_cmd = 'ARANGE ON';
67 }
68 elsif ( $range =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ ) {
69 0 $range_cmd = sprintf( "FUNC DCV %e", abs($range) );
70 }
71 elsif ( $range !~ /^(MIN|MAX)$/ ) {
72 0 Lab::Exception::CorruptParameter->throw( error =>
73 "Range has to be set to a decimal value or 'AUTO', 'MIN' or 'MAX' in "
74 . ( caller(0) )[3]
75 . "\n" );
76 }
77  
78 0 ▶ if ( !defined($tint) || $tint eq 'DEFAULT' ) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $tint or $tint eq 'DEFAULT') { } 0 0 0
elsif ($tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u and $tint >= 0 && $tint <= 1000 || $tint == -1) { } 0 0 0
elsif ($tint =~ /^MIN$/u) { } 0 0 0
elsif ($tint =~ /^MAX$/u) { } 0 0 0
elsif (not $tint =~ /^(MIN|MAX)$/u) { } 0 0 0
Condition0%0/3
not defined $tint or $tint eq "DEFAULT"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $tint or $tint eq "DEFAULT"
not defined $tint $tint eq "DEFAULT"
Truth table0%0/3
not(A) or B
A= not defined $tintB= $tint eq "DEFAULT"
ABresult
1X1
011
000
79 0 $tint = 10;
80 }
81 ▶ elsif ( $tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
Condition0%0/9
$tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u and $tint >= 0 && $tint <= 1000 || $tint == -1
!ll&&!rl&&r
000
$tint >= 0 and $tint <= 1000 or $tint == -1
l!l&&r!l&&!r
000
$tint >= 0 and $tint <= 1000
!ll&&!rl&&r
000
MC/DC0%0/4
$tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u and $tint >= 0 && $tint <= 1000 || $tint == -1
$tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u $tint >= 0 $tint <= 1000 $tint == -1
Truth table0%0/6
A and B and C or D
A= $tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/uB= $tint >= 0C= $tint <= 1000D= $tint == -1
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
82 && ( ( $tint >= 0 && $tint <= 1000 ) || $tint == -1 ) ) {
83  
84 # Convert seconds to PLC (power line cycles)
85 0 $tint *= $self->pl_freq();
86 }
87 elsif ( $tint =~ /^MIN$/ ) {
88 0 $tint = 0;
89 }
90 elsif ( $tint =~ /^MAX$/ ) {
91 0 $tint = 1000;
92 }
93 elsif ( $tint !~ /^(MIN|MAX)$/ ) {
94 0 Lab::Exception::CorruptParameter->throw( error =>
95 "Integration time has to be set to a positive value or 'AUTO', 'MIN' or 'MAX' in "
96 . ( caller(0) )[3]
97 . "\n" );
98 }
99  
100 # do it
101 0 $self->write( $range_cmd, error_check => 1 );
102 0 $self->write( "NPLC ${tint}", error_check => 1 );
103  
104 #$self->write( "NPLC ${tint}", { error_check=>1 });
105 }
106  
107 sub configure_voltage_dc_trigger {
108 0 ▶ my $self = shift;
Subroutine configure_voltage_dc_trigger: not called CC=8 SCAR=42.8
Pod documented
109  
110 0 my ( $range, $tint, $count, $delay )
111 = $self->_check_args( \@_, [ 'range', 'tint', 'count', 'delay' ] );
112  
113 0 ▶ $count = 1 if !defined($count);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 0 0
114 0 ▶ Lab::Exception::CorruptParameter->throw(
Branch: 1 branch
BranchTrueFalseTotal
if not $count =~ /^[0-9]*$/u or $count < 1 or $count > 16777215 0 0 0
Condition0%0/6
not $count =~ /^[0-9]*$/u or $count < 1 or $count > 16777215
l!l&&r!l&&!r
000
not $count =~ /^[0-9]*$/u or $count < 1
l!l&&r!l&&!r
000
MC/DC0%0/3
not $count =~ /^[0-9]*$/u or $count < 1 or $count > 16777215
not $count =~ /^[0-9]*$/u $count < 1 $count > 16777215
Truth table0%0/4
not(A) or B or C
A= not $count =~ /^[0-9]*$/uB= $count < 1C= $count > 16777215
ABCresult
1XX1
01X1
0011
0000
115 error => "Sample count has to be an integer between 1 and 512\n" )
116 if ( $count !~ /^[0-9]*$/ || $count < 1 || $count > 16777215 );
117  
118 0 ▶ $delay = 0 if !defined($delay);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $delay 0 0 0
119 0 ▶ Lab::Exception::CorruptParameter->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $count =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u 0 0 0
120 error => "Trigger delay has to be a positive decimal value\n" )
121 if ( $count !~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ );
122  
123 0 $self->configure_voltage_dc( $range, $tint );
124  
125 #$self->write( "PRESET NORM" );
126 0 ▶ if ( $count > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 1) { } 0 0 0
127 0 $self->write( "INBUF ON", error_check => 1 );
128 }
129 else {
130 0 $self->write( "INBUF OFF", error_check => 1 );
131 }
132 0 $self->write( "TARM AUTO", error_check => 1 );
133 0 $self->write( "TRIG HOLD", error_check => 1 );
134 0 $self->write( "NRDGS $count, AUTO", error_check => 1 );
135 0 $self->write( "TIMER $delay", error_check => 1 );
136  
137 #$self->write( "TRIG:DELay:AUTO OFF");
138 }
139  
140 sub configure_voltage_dc_trigger_highspeed {
141 0 ▶ my $self = shift;
Subroutine configure_voltage_dc_trigger_highspeed: not called CC=23 SCAR=63.1
Pod documented
142 0 ▶ my $range = shift || 10; # in V, or "AUTO", "MIN", "MAX"
Condition0%0/2
shift() || 10
l!l
00
MC/DC0%0/1
shift() || 10
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
143 0 ▶ my $tint = shift
Condition0%0/2
shift() || 1.4e-06
l!l
00
MC/DC0%0/1
shift() || 1.4e-06
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
144 || 1.4e-6
145 ; # integration time in sec, "DEFAULT", "MIN", "MAX". Default of 1.4e-6 is the highest possible value for 100kHz sampling.
146 0 ▶ my $count = shift || 10000;
Condition0%0/2
shift() || 10000
l!l
00
MC/DC0%0/1
shift() || 10000
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
147 0 my $delay = shift; # in seconds, 'MIN'
148  
149 0 ▶ if ( $range eq 'AUTO' || !defined($range) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($range eq 'AUTO' or not defined $range) { } 0 0 0
elsif ($range =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u) { } 0 0 0
elsif (not $range =~ /^(MIN|MAX)$/u) { } 0 0 0
Condition0%0/3
$range eq "AUTO" or not defined $range
l!l&&r!l&&!r
000
MC/DC0%0/2
$range eq "AUTO" or not defined $range
$range eq "AUTO" not defined $range
Truth table0%0/3
A or not(B)
A= $range eq "AUTO"B= not defined $range
ABresult
1X1
011
000
150 0 $range = 'AUTO';
151 }
152 elsif ( $range =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ ) {
153  
154 #$range = sprintf("%e",abs($range));
155 }
156 elsif ( $range !~ /^(MIN|MAX)$/ ) {
157 0 Lab::Exception::CorruptParameter->throw( error =>
158 "Range has to be set to a decimal value or 'AUTO', 'MIN' or 'MAX' in "
159 . ( caller(0) )[3]
160 . "\n" );
161 }
162  
163 0 ▶ if ( $tint eq 'DEFAULT' || !defined($tint) ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($tint eq 'DEFAULT' or not defined $tint) { } 0 0 0
elsif ($tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u and $tint >= 0 && $tint <= 1000 || $tint == -1) { } 0 0 0
elsif ($tint =~ /^MIN$/u) { } 0 0 0
elsif ($tint =~ /^MAX$/u) { } 0 0 0
elsif (not $tint =~ /^(MIN|MAX)$/u) { } 0 0 0
Condition0%0/3
$tint eq "DEFAULT" or not defined $tint
l!l&&r!l&&!r
000
MC/DC0%0/2
$tint eq "DEFAULT" or not defined $tint
$tint eq "DEFAULT" not defined $tint
Truth table0%0/3
A or not(B)
A= $tint eq "DEFAULT"B= not defined $tint
ABresult
1X1
011
000
164 0 $tint = 1.4e-6;
165 }
166 ▶ elsif ( $tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
Condition0%0/9
$tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u and $tint >= 0 && $tint <= 1000 || $tint == -1
!ll&&!rl&&r
000
$tint >= 0 and $tint <= 1000 or $tint == -1
l!l&&r!l&&!r
000
$tint >= 0 and $tint <= 1000
!ll&&!rl&&r
000
MC/DC0%0/4
$tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u and $tint >= 0 && $tint <= 1000 || $tint == -1
$tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u $tint >= 0 $tint <= 1000 $tint == -1
Truth table0%0/6
A and B and C or D
A= $tint =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/uB= $tint >= 0C= $tint <= 1000D= $tint == -1
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
167 && ( ( $tint >= 0 && $tint <= 1000 ) || $tint == -1 ) ) {
168  
169 # Convert seconds to PLC (power line cycles)
170 #$tint*=$self->pl_freq();
171 }
172 elsif ( $tint =~ /^MIN$/ ) {
173 0 $tint = 0;
174 }
175 elsif ( $tint =~ /^MAX$/ ) {
176 0 $tint = 1000;
177 }
178 elsif ( $tint !~ /^(MIN|MAX)$/ ) {
179 0 Lab::Exception::CorruptParameter->throw( error =>
180 "Integration time has to be set to a positive value or 'AUTO', 'MIN' or 'MAX' in "
181 . ( caller(0) )[3]
182 . "\n" );
183 }
184  
185 0 ▶ $count = 1 if !defined($count);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 0 0
186 0 ▶ Lab::Exception::CorruptParameter->throw(
Branch: 1 branch
BranchTrueFalseTotal
if not $count =~ /^[0-9]*$/u or $count < 1 or $count > 16777215 0 0 0
Condition0%0/6
not $count =~ /^[0-9]*$/u or $count < 1 or $count > 16777215
l!l&&r!l&&!r
000
not $count =~ /^[0-9]*$/u or $count < 1
l!l&&r!l&&!r
000
MC/DC0%0/3
not $count =~ /^[0-9]*$/u or $count < 1 or $count > 16777215
not $count =~ /^[0-9]*$/u $count < 1 $count > 16777215
Truth table0%0/4
not(A) or B or C
A= not $count =~ /^[0-9]*$/uB= $count < 1C= $count > 16777215
ABCresult
1XX1
01X1
0011
0000
187 error => "Sample count has to be an integer between 1 and 512\n" )
188 if ( $count !~ /^[0-9]*$/ || $count < 1 || $count > 16777215 );
189  
190 0 ▶ $delay = 0 if !defined($delay);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $delay 0 0 0
191 0 ▶ Lab::Exception::CorruptParameter->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $count =~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u 0 0 0
192 error => "Trigger delay has to be a positive decimal value\n" )
193 if ( $count !~ /^([+]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ );
194  
195 0 $self->write( "PRESET FAST", error_check => 1 );
196 0 $self->write( "TARM HOLD", error_check => 1 );
197 0 $self->write( "APER " . $tint, error_check => 1 );
198 0 $self->write( "MFORMAT SINT", error_check => 1 );
199 0 $self->write( "OFORMAT SINT", error_check => 1 );
200 0 $self->write( "MEM FIFO", error_check => 1 );
201 0 $self->write( "NRDGS $count, AUTO", error_check => 1 );
202  
203 #$self->write( "TIMER $delay") if defined($delay);
204  
205 }
206  
207 sub triggered_read {
208 0 ▶ my $self = shift;
Subroutine triggered_read: not called CC=5 SCAR=34.0
Pod undocumented
209 0 ▶ my $args
Branch: 2 branches
BranchTrueFalseTotal
scalar(@_) % 2 == 0 ? : 0 0 0
ref $_[0] eq 'HASH' ? : 0 0 0
210 = scalar(@_) % 2 == 0
211 ? {@_}
212 : ( ref( $_[0] ) eq 'HASH' ? $_[0] : undef );
213 0 ▶ Lab::Exception::CorruptParameter->throw("Illegal parameter hash given!\n")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args 0 0 0
214 if !defined($args);
215  
216 0 ▶ $args->{'timeout'} = $args->{'timeout'} || undef;
Condition0%0/2
$args->{'timeout'} || undef
l!l
00
MC/DC0%0/1
$args->{'timeout'} || undef
$args->{'timeout'}
Truth table0%0/2
A
A= $args->{'timeout'}
Aresult
11
00
217  
218 0 my $value = $self->query( "TRIG SGL", $args );
219  
220 0 chomp $value;
221  
222 0 my @valarray = split( "\n", $value );
223  
224 0 return @valarray;
225 }
226  
227 sub triggered_read_raw {
228 0 ▶ my $self = shift;
Subroutine triggered_read_raw: not called CC=6 SCAR=34.3
Pod documented
229 0 ▶ my $args
Branch: 2 branches
BranchTrueFalseTotal
scalar(@_) % 2 == 0 ? : 0 0 0
ref $_[0] eq 'HASH' ? : 0 0 0
230 = scalar(@_) % 2 == 0
231 ? {@_}
232 : ( ref( $_[0] ) eq 'HASH' ? $_[0] : undef );
233 0 ▶ Lab::Exception::CorruptParameter->throw("Illegal parameter hash given!\n")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args 0 0 0
234 if !defined($args);
235  
236 0 my $read_until_length = $args->{'read_until_length'};
237 0 my $value = '';
238 0 my $fragment = undef;
239  
240 {
241 1 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.2
242 0 $value = $self->query( "TARM SGL", $args );
243 0 my $tmp = length($value);
244 0 ▶ while ( defined $read_until_length
Branch: 1 branch
BranchTrueFalseTotal
if (defined $read_until_length and length $value < $read_until_length) 0 0 0
Condition0%0/3
defined $read_until_length and length $value < $read_until_length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $read_until_length and length $value < $read_until_length
defined $read_until_length length $value < $read_until_length
Truth table0%0/3
A and B
A= defined $read_until_lengthB= length $value < $read_until_length
ABresult
0X0
100
111
245 && length($value) < $read_until_length ) {
246 0 $value .= $self->read($args);
247 }
248 }
249  
250 0 return $value;
251 }
252  
253 sub decode_SINT {
254 1 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
255 0 ▶ my $self = shift;
Subroutine decode_SINT: not called CC=6 SCAR=37.4
Pod documented
256 0 my $bytestring = shift;
257 0 ▶ my $iscale = shift || $self->query('ISCALE?');
Condition0%0/3
shift() || $self->query('ISCALE?')
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->query('ISCALE?')
shift() $self->query('ISCALE?')
Truth table0%0/3
A || B
A= shift()B= $self->query('ISCALE?')
ABresult
1X1
011
000
258  
259 0 my @values = split( //, $bytestring );
260 0 my $ival = 0;
261 0 my $val_revb = 0;
262 0 my $tbyte = 0;
263 0 my $value = 0;
264 0 my @result_list = ();
265 0 my $i = 0;
266 0 ▶ for ( my $v = 0; $v < $#values; $v += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v < $#values) 0 0 0
267 0 $ival = unpack( 'S', join( '', $values[$v], $values[ $v + 1 ] ) );
268  
269 # flipping the bytes to MSB,...,LSB
270 0 $val_revb = 0;
271 0 ▶ for ( $i = 0; $i < 2; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 2) 0 0 0
272 0 $val_revb = $val_revb
273 | ( ( $ival >> $i * 8 & 0x000000FF ) << ( ( 1 - $i ) * 8 ) );
274 }
275  
276 0 my $decval = 0;
277 0 my $msb = ( $val_revb >> 15 ) & 0x0001;
278 0 ▶ $decval = $msb == 0 ? 0 : -1 * ( 2**15 );
Branch: 1 branch
BranchTrueFalseTotal
$msb == 0 ? : 0 0 0
279 0 ▶ for ( $i = 14; $i >= 0; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
280 0 $decval += ( ( ( $val_revb >> $i ) & 0x0001 ) * 2 )**$i;
281 }
282 0 push( @result_list, $decval * $iscale );
283 }
284 0 return @result_list;
285 }
286  
287 sub set_oformat {
288 0 ▶ my $self = shift;
Subroutine set_oformat: not called CC=2 SCAR=17.9
Pod undocumented
289 0 my $format = shift;
290  
291 0 ▶ if ( $format !~ /^\s*(ASCII|1|SINT|2|DINT|3|SREAD|4|DREAL|5)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($format =~ /^\s*(ASCII|1|SINT|2|DINT|3|SREAD|4|DREAL|5)\s*$/u) 0 0 0
292 0 Lab::Exception::CorruptParameter->throw("Invalid OFORMAT specified.");
293 }
294 0 $format = $1;
295  
296 0 $self->write("OFORMAT $1");
297  
298 0 $self->check_errors();
299 }
300  
301 sub get_oformat {
302 0 ▶ my $self = shift;
Subroutine get_oformat: not called CC=6 SCAR=37.4
Pod undocumented
303 0 ▶ my $args
Branch: 2 branches
BranchTrueFalseTotal
scalar(@_) % 2 == 0 ? : 0 0 0
ref $_[0] eq 'HASH' ? : 0 0 0
304 = scalar(@_) % 2 == 0
305 ? {@_}
306 : ( ref( $_[0] ) eq 'HASH' ? $_[0] : undef );
307 0 ▶ Lab::Exception::CorruptParameter->throw("Illegal parameter hash given!\n")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args 0 0 0
308 if !defined($args);
309  
310 0 ▶ if ( $args->{direct_read} || !defined $self->device_cache()->{oformat} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'direct_read'} or not defined $self->device_cache->{'oformat'}) { } 0 0 0
Condition0%0/3
$args->{"direct_read"} or not defined $self->device_cache->{"oformat"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"direct_read"} or not defined $self->device_cache->{"oformat"}
$args->{"direct_read"} not defined $self->device_cache->{"oformat"}
Truth table0%0/3
A or not(B)
A= $args->{"direct_read"}B= not defined $self->device_cache->{"oformat"}
ABresult
1X1
011
000
311 return $self->device_cache()->{oformat}
312 0 = $self->query( 'OFORMAT?', $args );
313 }
314 else {
315 0 return $self->device_cache()->{oformat};
316 }
317 }
318  
319 sub get_autozero {
320 0 ▶ my $self = shift;
Subroutine get_autozero: not called CC=1 SCAR=6.9
Pod undocumented
321  
322 return $self->device_cache()->{autozero}
323 0 = $self->query( 'AZERO?', @_, error_check => 0 );
324 }
325  
326 sub set_autozero {
327 0 ▶ my $self = shift;
Subroutine set_autozero: not called CC=4 SCAR=30.0
Pod undocumented
328 0 my $enable = shift;
329  
330 0 my $command = "";
331 0 my $cval = undef;
332  
333 0 ▶ if ( $enable =~ /^ONCE$/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($enable =~ /^ONCE$/iu) { } 0 0 0
elsif ($enable =~ /^(ON|1)$/iu) { } 0 0 0
elsif ($enable =~ /^(OFF|0)$/iu) { } 0 0 0
334 0 $command = "AZERO ONCE";
335 0 $cval = 0;
336 }
337 elsif ( $enable =~ /^(ON|1)$/i ) {
338 0 $command = "AZERO ON";
339 0 $cval = 1;
340 }
341 elsif ( $enable =~ /^(OFF|0)$/i ) {
342 0 $command = "AZERO OFF";
343 0 $cval = 0;
344 }
345 else {
346 0 Lab::Exception::CorruptParameter->throw( error => ( caller(0) )[3]
347 . " can be set to 'ON'/1, 'OFF'/0 or 'ONCE'. Received '${enable}'\n"
348 );
349 }
350 0 $self->write( $command, error_check => 1, @_ );
351  
352 0 $self->device_cache()->{autozero} = $cval;
353 }
354  
355 sub get_voltage_dc {
356 0 ▶ my $self = shift;
Subroutine get_voltage_dc: not called CC=1 SCAR=6.9
Pod documented
357  
358 0 $self->write( "DCV AUTO", @_ );
359 0 $self->write( "TARM SGL", @_ );
360 0 return $self->read(@_);
361 }
362  
363 sub set_nplc {
364 0 ▶ my $self = shift;
Subroutine set_nplc: not called CC=1 SCAR=6.9
Pod documented
365 0 my $n = shift;
366  
367 0 $self->write( "NPLC $n", @_ );
368 }
369  
370 sub selftest {
371 0 ▶ my $self = shift;
Subroutine selftest: not called CC=1 SCAR=6.9
Pod documented
372  
373 0 $self->write( "TEST", @_ );
374 }
375  
376 sub autocalibration {
377 0 ▶ my $self = shift;
Subroutine autocalibration: not called CC=2 SCAR=17.9
Pod documented
378 0 my $mode = shift;
379  
380 0 ▶ if ( $mode !~ /^(ALL|0|DCV|1|DIG|2|OHMS|4)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode =~ /^(ALL|0|DCV|1|DIG|2|OHMS|4)$/iu) 0 0 0
381 0 Lab::Exception::CorruptParameter->throw(
382 "preset(): Illegal preset mode given: $mode\n");
383 }
384  
385 0 $self->write( "ACAL \U$mode\E", @_ );
386 }
387  
388 sub reset {
389 0 ▶ my $self = shift;
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
390  
391 0 $self->write( "PRESET NORM", @_ );
392 }
393  
394 sub set_display_state {
395 0 ▶ my $self = shift;
Subroutine set_display_state: not called CC=5 SCAR=34.0
Pod documented
396 0 my $value = shift;
397  
398 0 ▶ if ( $value == 1 || $value =~ /on/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value == 1 or $value =~ /on/iu) { } 0 0 0
elsif ($value == 0 or $value =~ /off/iu) { } 0 0 0
Condition0%0/3
$value == 1 or $value =~ /on/iu
l!l&&r!l&&!r
000
MC/DC0%0/2
$value == 1 or $value =~ /on/iu
$value == 1 $value =~ /on/iu
Truth table0%0/3
A or B
A= $value == 1B= $value =~ /on/iu
ABresult
1X1
011
000
399 0 $self->write( "DISP ON", @_ );
400 }
401 ▶ elsif ( $value == 0 || $value =~ /off/i ) {
Condition0%0/3
$value == 0 or $value =~ /off/iu
l!l&&r!l&&!r
000
MC/DC0%0/2
$value == 0 or $value =~ /off/iu
$value == 0 $value =~ /off/iu
Truth table0%0/3
A or B
A= $value == 0B= $value =~ /off/iu
ABresult
1X1
011
000
402 0 $self->write( "DISP OFF", @_ );
403 }
404 else {
405 0 Lab::Exception::CorruptParameter->throw(
406 "set_display_state(): Illegal parameter.\n");
407 }
408 }
409  
410 sub display_clear {
411 0 ▶ my $self = shift;
Subroutine display_clear: not called CC=1 SCAR=6.9
Pod documented
412  
413 0 $self->write( "DISP CLR", @_ );
414 }
415  
416 sub set_display_text {
417 0 ▶ my $self = shift;
Subroutine set_display_text: not called CC=2 SCAR=17.9
Pod documented
418 0 my $text = shift;
419 0 ▶ if ( $text
Branch: 1 branch
BranchTrueFalseTotal
unless ($text =~ m{^[A-Za-z0-9\ \!\#\$\%\&\'\(\)\^\\/\@\;\:\[\]\,\.\+\-\=\<\>\?\_]*$}u) 0 0 0
420 !~ /^[A-Za-z0-9\ \!\#\$\%\&\'\(\)\^\\\/\@\;\:\[\]\,\.\+\-\=\<\>\?\_]*$/
421 ) { # characters allowed by the 3458A
422 0 Lab::Exception::CorruptParameter->throw(
423 "set_display_text(): Illegal characters in given text.\n");
424 }
425 0 $self->write("DISP MSG,\"$text\"");
426  
427 0 $self->check_errors();
428 }
429  
430 sub beep {
431  
432 # It beeps!
433 0 ▶ my $self = shift;
Subroutine beep: not called CC=1 SCAR=6.9
Pod documented
434 0 $self->write( "BEEP", @_ );
435 }
436  
437 sub get_status {
438 0 ▶ my $self = shift;
Subroutine get_status: not called CC=2 SCAR=17.9
Pod documented
439 0 my $request = shift;
440 0 my $status = {};
441 (
442 $status->{PRG_COMPLETE}, $status->{LIMIT_EXCEEDED},
443 $status->{SRQ_EXECUTED}, $status->{POWER_ON},
444 $status->{READY}, $status->{ERROR},
445 $status->{SRQ}, $status->{DATA}
446 0 ) = $self->connection()->serial_poll();
447 0 ▶ return $status->{$request} if defined $request;
Branch: 1 branch
BranchTrueFalseTotal
if defined $request 0 0 0
448 0 return $status;
449 }
450  
451 sub get_error {
452 0 ▶ my $self = shift;
Subroutine get_error: not called CC=3 SCAR=24.8
Pod documented
453 0 my $error = $self->query( "ERRSTR?", brutal => 1, @_ );
454 0 ▶ if ( $error !~ /0,\"NO ERROR\"/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $error =~ /0,\"NO ERROR\"/u) { } 0 0 0
455 0 ▶ if ( $error =~ /^\+?([0-9]*)\,\"?([^\"].*[^\"])\"?$/m ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /^\+?([0-9]*)\,\"?([^\"].*[^\"])\"?$/mu) { } 0 0 0
456 0 return ( $1, $2 ); # ($code, $message)
457 }
458 else {
459 0 Lab::Exception::DeviceError->throw(
460 "Reading the error status of the device failed in "
461 . ( caller(0) )[3]
462 . ". Something's going wrong here.\n" );
463 }
464 }
465 else {
466 0 return (0);
467 }
468 }
469  
470 sub preset {
471  
472 # Sets HP3458A into predefined configurations
473 # 0 Fast
474 # 1 Norm
475 # 2 DIG
476 0 ▶ my $self = shift;
Subroutine preset: not called CC=2 SCAR=17.9
Pod documented
477 0 my $preset = shift;
478 0 ▶ if ( $preset !~ /^(FAST|0|NORM|1|DIG|2)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($preset =~ /^(FAST|0|NORM|1|DIG|2)$/iu) 0 0 0
479 0 Lab::Exception::CorruptParameter->throw(
480 "preset(): Illegal preset mode given: $preset\n");
481 }
482  
483 0 $self->write( "PRESET \U$preset\E", @_ );
484 }
485  
486 sub get_id {
487 0 ▶ my $self = shift;
Subroutine get_id: not called CC=1 SCAR=6.9
Pod undocumented
488 0 return $self->query( 'ID?', @_ );
489 }
490  
491 sub trg {
492 0 ▶ my $self = shift;
Subroutine trg: not called CC=1 SCAR=6.9
Pod undocumented
493 0 $self->write( 'TRIG SGL', @_ );
494 }
495  
496 sub get_value {
497  
498 0 ▶ my $self = shift;
Subroutine get_value: not called CC=1 SCAR=6.9
Pod documented
499  
500 0 my $val = $self->read(@_);
501 0 chomp $val;
502 0 return $val;
503 }
504  
505 1 1;
506  
507 __END__
508  
509 =pod
510  
511 =encoding utf-8
512  
513 =head1 NAME
514  
515 Lab::Instrument::HP3458A - Agilent 3458A Multimeter
516  
517 =head1 VERSION
518  
519 version 3.881
520  
521 =head1 SYNOPSIS
522  
523 use Lab::Instrument::HP3458A;
524
525 my $dmm=new Lab::Instrument::HP3458A({
526 gpib_board => 0,
527 gpib_address => 11,
528 });
529 print $dmm->get_voltage_dc();
530  
531 =head1 DESCRIPTION
532  
533 The Lab::Instrument::HP3458A class implements an interface to the Agilent / HP
534 3458A digital multimeter.
535  
536 =head1 CONSTRUCTOR
537  
538 my $hp=new(%parameters);
539  
540 =head1 METHODS
541  
542 =head2 pl_freq
543 Parameter: pl_freq
544  
545 $hp->pl_freq($new_freq);
546 $npl_freq = $hp->pl_freq();
547  
548 Get/set the power line frequency at your location (50 Hz for most countries, which is the default). This
549 is the basis of the integration time setting (which is internally specified as a count of power
550 line cycles, or PLCs). The integration time will be set incorrectly if this parameter is set incorrectly.
551  
552 =head2 get_voltage_dc
553  
554 $voltage=$hp->get_voltage_dc();
555  
556 Make a dc voltage measurement. This also enables autoranging. For finer control, use configure_voltage_dc() and
557 triggered_read.
558  
559 _head2 triggered_read
560  
561 @values = $hp->triggered_read();
562 $value = $hp->triggered_read();
563  
564 Trigger and read value(s) using the current device setup. This expects and digests a list of values in ASCII format,
565 as set up by configure_voltage_dc().
566  
567 =head2 triggered_read_raw
568  
569 $result = $hp->triggered_read_raw( read_until_length => $length );
570  
571 Trigger and read using the current device setup. This won't do any parsing and just return the answer from the device.
572 If $read_until_length (integer) is specified, it will try to continuously read until it has gathered this amount of bytes.
573  
574 =head2 configure_voltage_dc
575  
576 $hp->configure_voltage_dc($range, $integration_time);
577  
578 Configure range and integration time for the following DCV measurements.
579  
580 $range is a voltage or one of "AUTO", "MIN" or "MAX".
581 $integration_time is given in seconds or one of "DEFAULT", "MIN" or "MAX".
582  
583 =head2 configure_voltage_dc_trigger
584  
585 $hp->configure_voltage_dc_trigger($range, $integration_time,
586 $count, $delay);
587  
588 Configures range, integration time, sample count and delay (between samples) for triggered
589 readings.
590  
591 $range, $integration_time: see configure_voltage_dc().
592 $count is the sample count per trigger (integer).
593 $delay is the delay between the samples in seconds.
594  
595 =head2 configure_voltage_dc_trigger_highspeed
596  
597 $hp->configure_voltage_dc_trigger_highspeed($range,
598 $integration_time, $count, $delay);
599  
600 Same as configure_voltage_dc_trigger, but configures the device for maximum measurement speed.
601 Values are transferred in SINT format and can be fetched and decoded using triggered_read_raw()
602 and decode_SINT().
603 This mode allows measurements of up to about 100 kSamples/second.
604  
605 $range: see configure_voltage_dc().
606 $integration_time: integration time in seconds. The default is 1.4e-6.
607 $count is the sample count per trigger (integer).
608 $delay is the delay between the samples in seconds.
609  
610 =head2 set_display_state
611  
612 $hp->set_display_state($state);
613  
614 Turn the front-panel display on/off. $state can be
615 each of '1', '0', 'on', 'off'.
616  
617 =head2 set_display_text
618  
619 $hp->set_display_text($text);
620  
621 Display a message on the front panel. The multimeter will display up to 12
622 characters in a message; any additional characters are truncated.
623  
624 =head2 display_clear
625  
626 $hp->display_clear();
627  
628 Clear the message displayed on the front panel.
629  
630 =head2 beep
631  
632 $hp->beep();
633  
634 Issue a single beep immediately.
635  
636 =head2 get_error
637  
638 ($err_num,$err_msg)=$hp->get_error();
639  
640 Query the multimeter's error queue. Up to 20 errors can be stored in the
641 queue. Errors are retrieved in first-in-first out (FIFO) order.
642  
643 =head2 check_errors
644  
645 $instrument->check_errors($last_command);
646
647 # try
648 eval { $instrument->check_errors($last_command) };
649 # catch
650 if ( my $e = Exception::Class->caught('Lab::Exception::DeviceError')) {
651 warn "Errors from device!";
652 @errors = $e->error_list();
653 @devtype = $e->device_class();
654 $command = $e->command();
655 } else {
656 $e = Exception::Class->caught();
657 ref $e ? $e->rethrow; die $e;
658 }
659  
660 Uses get_error() to check the device for occured errors. Reads all present error and throws a
661 Lab::Exception::DeviceError. The list of errors, the device class and the last issued command(s)
662 (if the script provided them) are enclosed.
663  
664 =head2 set_nplc
665  
666 $hp->set_nplc($number);
667  
668 Sets the integration time in units of power line cycles.
669  
670 =head2 reset
671  
672 $hp->reset();
673  
674 Reset the multimeter to its power-on configuration. Same as preset('NORM').
675  
676 =head2 preset
677  
678 $hp->preset($config);
679  
680 $config can be any of the following settings:
681  
682 'FAST' / 0
683 'NORM' / 1
684 'DIG' / 2
685  
686 Choose one of several configuration presets.
687  
688 =head2 selftest
689  
690 $hp->selftest();
691  
692 Starts the internal self-test routine.
693  
694 =head2 autocalibration
695  
696 $hp->autocalibration($mode);
697  
698 Starts the internal autocalibration. Warning... this procedure takes 11 minutes with the 'ALL' mode!
699  
700 $mode can be each of
701  
702 'ALL' / 0
703 'DCV' / 1
704 'AC' / 2
705 'OHMS' / 4
706  
707 =head2 decode_SINT
708  
709 @values = $hp->decode_SINT( $SINT_data, <$iscale> );
710  
711 Takes a data blob with SINT values and decodes them into a numeric list. The used $iscale parameter is
712 read from the device by default if omitted. Make sure the device still has the same settings as used to
713 obtain $SINT_data, or iscale will be off which leads to invalid data decoding.
714  
715 =head1 CAVEATS/BUGS
716  
717 probably many
718  
719 =head1 SEE ALSO
720  
721 =over 4
722  
723 =item * L<Lab::Instrument>
724  
725 =item * L<Lab::Instrument::Multimeter>
726  
727 =back
728  
729 =head1 COPYRIGHT AND LICENSE
730  
731 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
732  
733 Copyright 2011 Andreas K. Huettel, Florian Olbrich
734 2012 Alois Dirnaichner, Andreas K. Huettel, Florian Olbrich
735 2013 Alois Dirnaichner, Andreas K. Huettel
736 2015 Alois Dirnaichner
737 2016 Simon Reinhardt
738 2017 Andreas K. Huettel
739 2020 Andreas K. Huettel
740  
741  
742 This is free software; you can redistribute it and/or modify it under
743 the same terms as the Perl 5 programming language system itself.
744  
745 =cut
« Instrument/Keithley2000.pm ↑ Summary Bus/USBtmc.pm »