Moose/Instrument/KeysightB2901A.pm

filter: Statementstmt 82.3% 56 / 68 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.2% 16 / 19 Podpod 50.0% 5 / 10 totaltotal 79.3% 77 / 97 SCAR 0.1
CC
1
Cov
82%
sense_function_concurrent
2.0
get_measurement
2.0
set_voltage
2.0
CRAP 1.0
« Moose/Instrument/Keithley2400.pm ↑ Summary Moose/Instrument/SCPI/Display/Window.pm »
1 package Lab::Moose::Instrument::KeysightB2901A;
2 2 $Lab::Moose::Instrument::KeysightB2901A::VERSION = '3.881';
3 #ABSTRACT: Agilent/Keysight B2901A voltage/current sourcemeter.
4  
5 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 use Lab::Moose::Instrument
11 2 ▶ qw/validated_getter validated_setter setter_params/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Lab::Moose::Instrument::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 extends 'Lab::Moose::Instrument';
17  
18 2 has [qw/max_units_per_second max_units_per_step min_units max_units/] =>
19 ( is => 'ro', isa => 'Num', required => 1 );
20  
21 2 has source_level_timestamp => (
22 is => 'rw',
23 isa => 'Num',
24 init_arg => undef,
25 );
26  
27 2 has verbose => (
28 is => 'ro',
29 isa => 'Bool',
30 default => 1
31 );
32  
33 sub BUILD {
34 1 ▶ my $self = shift;
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
35  
36 1 $self->clear();
37 1 $self->cls();
38 }
39  
40 around default_connection_options => sub {
41 1 ▶ my $orig = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
42 1 my $self = shift;
43 1 my $options = $self->$orig();
44 1 my $usb_opts = {
45 vid => 0x0957, pid => 0x8b18, # Agilent vid!
46 reset_device => 0
47 , # Problem of the B2901A: https://community.keysight.com/thread/36706
48 };
49 1 $options->{USB} = $usb_opts;
50 1 $options->{'VISA::USB'} = $usb_opts;
51 1 return $options;
52 2 };
53  
54  
55 sub source_function_query {
56 2 ▶ my ( $self, %args ) = validated_getter( \@_ );
Subroutine source_function_query: called CC=1 SCAR=0.0
Pod undocumented
57  
58 2 my $value = $self->query( command => "SOUR:FUNC:MODE?", %args );
59 2 $value =~ s/["']//g;
60 2 return $self->cached_source_function($value);
61 }
62  
63 sub source_function {
64 2 ▶ my ( $self, $value, %args ) = validated_setter( \@_ );
Subroutine source_function: called CC=1 SCAR=0.0
Pod undocumented
65 2 $self->write( command => "SOUR:FUNC:MODE $value", %args );
66 2 $self->cached_source_function($value);
67 }
68  
69 # Concurrent sense is always ON for the B2901A
70 sub sense_function_concurrent_query {
71 1 ▶ return 1;
Subroutine sense_function_concurrent_query: called CC=1 SCAR=0.0
Pod undocumented
72 }
73  
74 sub sense_function_concurrent {
75 0 ▶ croak "Concurrent sense is always ON";
Subroutine sense_function_concurrent: not called CC=1 SCAR=6.9
Pod undocumented
76 }
77  
78  
79 sub set_level {
80 1 ▶ my ( $self, $value, %args ) = validated_setter(
Subroutine set_level: called CC=1 SCAR=0.0
Pod documented
81 \@_,
82 value => { isa => 'Num' },
83 );
84  
85 1 return $self->linear_step_sweep(
86 to => $value, verbose => $self->verbose,
87 %args
88 );
89 }
90  
91  
92 sub get_measurement {
93 0 ▶ my ( $self, %args ) = validated_getter( \@_ );
Subroutine get_measurement: not called CC=1 SCAR=6.9
Pod documented
94 0 my $meas = $self->query( command => ':MEAS?', %args );
95 0 my $elements = $self->query( command => ':FORM:ELEM:SENS?' );
96 0 my @elements = split /,/, $elements;
97 0 my @meas_values = split /,/, $meas;
98 0 my %result = map { $_ => shift @meas_values } @elements;
99 0 return \%result;
100 }
101  
102 #
103 # Aliases for Lab::XPRESS::Sweep API
104 #
105  
106  
107 sub cached_level {
108 1 ▶ my $self = shift;
Subroutine cached_level: called CC=1 SCAR=0.0
Pod documented
109 1 return $self->cached_source_level(@_);
110 }
111  
112  
113 sub get_level {
114 1 ▶ my $self = shift;
Subroutine get_level: called CC=1 SCAR=0.0
Pod documented
115 1 return $self->source_level_query(@_);
116 }
117  
118  
119 sub set_voltage {
120 0 ▶ my $self = shift;
Subroutine set_voltage: not called CC=1 SCAR=6.9
Pod documented
121 0 my $value = shift;
122 0 return $self->set_level( value => $value );
123 }
124  
125 2 with qw(
126 Lab::Moose::Instrument::Common
127 Lab::Moose::Instrument::SCPI::Sense::Function::Concurrent
128 Lab::Moose::Instrument::SCPI::Sense::Protection
129 Lab::Moose::Instrument::SCPI::Sense::Range
130 Lab::Moose::Instrument::SCPI::Sense::NPLC
131 Lab::Moose::Instrument::SCPI::Source::Function
132 Lab::Moose::Instrument::SCPI::Source::Level
133 Lab::Moose::Instrument::SCPI::Source::Range
134 Lab::Moose::Instrument::LinearStepSweep
135 );
136  
137 after source_level => sub {
138 17 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
139  
140 # B2901A (with GPIB) accepts "SOUR:VOLT:LEV" in a faster rate than
141 # it can set the value. Slow it down by doing a query after each set.
142 17 $self->source_level_query();
143 2 };
144  
145 2 __PACKAGE__->meta()->make_immutable();
146  
147 2 1;
148  
149 __END__
150  
151 =pod
152  
153 =encoding UTF-8
154  
155 =head1 NAME
156  
157 Lab::Moose::Instrument::KeysightB2901A - Agilent/Keysight B2901A voltage/current sourcemeter.
158  
159 =head1 VERSION
160  
161 version 3.881
162  
163 =head1 SYNOPSIS
164  
165 use Lab::Moose;
166  
167 my $source = instrument(
168 type => 'KeysightB2901A',
169 connection_type => 'LinuxGPIB',
170 connection_options => {gpib_address => 15},
171 # mandatory protection settings
172 max_units_per_step => 0.001, # max step is 1mV/1mA
173 max_units_per_second => 0.01,
174 min_units => -10,
175 max_units => 10,
176 );
177  
178 ### Sourcing
179  
180  
181 # Source voltage
182 $source->source_function(value => 'VOLT');
183 $source->source_range(value => 210);
184
185 # Step-sweep to new level.
186 # Stepsize and speed is given by (max|min)_units* settings.
187 $source->set_level(value => 9);
188  
189 # Get current level from device cache (without sending a query to the
190 # instrument):
191 my $level = $source->cached_level();
192  
193 ### Measurement
194  
195 The B2901A provides a concurrent SENSE subsystem. See also L<Lab::Moose::Instrument::SCPI::Sense::Function::Concurrent>.
196  
197 # Measure current
198 $source->sense_function_on(value => ['CURR']);
199 $source->sense_function(value => 'CURR');
200 # Set measurement range to 100nA
201 $source->sense_range(value => 100e-9);
202 # Use measurement integration time of 2 NPLC
203 $source->sense_nplc(value => 2);
204 # Set compliance limit to 10nA
205 $source->sense_protection(value => 10e-9);
206
207 # Get measurement sample
208 my $sample = $source->get_measurement();
209 my $current = $sample->{CURR};
210 # print all entries in sample (Voltage, Current, Resistance, Timestamp):
211 use Data::Dumper;
212 print Dumper $sample;
213  
214 =head1 NOTES
215  
216 There are problems with the USB connection:
217 L<https://community.keysight.com/thread/36706>. GPIB works fine.
218  
219 =head1 METHODS
220  
221 Used roles:
222  
223 =over
224  
225 =item L<Lab::Moose::Instrument::Common>
226  
227 =item L<Lab::Moose::Instrument::SCPI::Sense::Function::Concurrent>
228  
229 =item L<Lab::Moose::Instrument::SCPI::Sense::Protection>
230  
231 =item L<Lab::Moose::Instrument::SCPI::Sense::Range>
232  
233 =item L<Lab::Moose::Instrument::SCPI::Sense::NPLC>
234  
235 =item L<Lab::Moose::Instrument::SCPI::Source::Function>
236  
237 =item L<Lab::Moose::Instrument::SCPI::Source::Level>
238  
239 =item L<Lab::Moose::Instrument::SCPI::Source::Range>
240  
241 =item L<Lab::Moose::Instrument::LinearStepSweep>
242  
243 =back
244  
245 =head2 set_level
246  
247 $source->set_level(value => $new_level);
248  
249 Go to new level. Sweep with multiple steps if the distance between current and
250 new level is larger than C<max_units_per_step>.
251  
252 =head2 get_measurement
253  
254 my $sample = $source->get_measurement();
255 my $current = $sample->{CURR};
256  
257 Do new measurement and return sample hashref of measured elements.
258  
259 =head2 cached_level
260  
261 my $current_level = $source->cached_level();
262  
263 Get current value from device cache.
264  
265 =head2 get_level
266  
267 my $current_level = $source->get_level();
268  
269 Query current level.
270  
271 =head2 set_voltage
272  
273 $source->set_voltage($value);
274  
275 For XPRESS voltage sweep. Equivalent to C<< set_level(value => $value) >>.
276  
277 =head1 COPYRIGHT AND LICENSE
278  
279 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
280  
281 Copyright 2018-2019 Simon Reinhardt
282 2020 Andreas K. Huettel
283  
284  
285 This is free software; you can redistribute it and/or modify it under
286 the same terms as the Perl 5 programming language system itself.
287  
288 =cut
« Moose/Instrument/Keithley2400.pm ↑ Summary Moose/Instrument/SCPI/Display/Window.pm »