Moose/Instrument/KeysightB2901A.pm

filter: Statementstmt 81.6% 58 / 71 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.2% 16 / 19 Podpod 50.0% 5 / 10 totaltotal 78.4% 80 / 102 CC 2 SCAR 2.3
CC
2
Cov
81%
set_level
2.1
sense_function_concurrent
2.0
get_measurement
2.0
CRAP 1.3
« Moose/Instrument/OI_ILM210.pm ↑ Summary Moose/Instrument/RS_ZVM.pm »
1 package Lab::Moose::Instrument::KeysightB2901A;
2 2 $Lab::Moose::Instrument::KeysightB2901A::VERSION = '3.931';
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 1 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
34 1 my $self = shift;
35  
36 1 $self->clear();
37 1 $self->cls();
38 }
39  
40 1 ▶around default_connection_options => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
41 1 my $orig = shift;
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 2 ▶sub source_function_query {
Subroutine source_function_query: called CC=1 SCAR=0.0
Pod undocumented
56 2 my ( $self, %args ) = validated_getter( \@_ );
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 2 ▶sub source_function {
Subroutine source_function: called CC=1 SCAR=0.0
Pod undocumented
64 2 my ( $self, $value, %args ) = validated_setter( \@_ );
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 1 ▶sub sense_function_concurrent_query {
Subroutine sense_function_concurrent_query: called CC=1 SCAR=0.0
Pod undocumented
71 1 return 1;
72 }
73  
74 0 ▶sub sense_function_concurrent {
Subroutine sense_function_concurrent: not called CC=1 SCAR=6.9
Pod undocumented
75 0 croak "Concurrent sense is always ON";
76 }
77  
78  
79 1 ▶sub set_level {
Subroutine set_level: called CC=2 SCAR=7.4
Pod documented
80 1 my ( $self, $value, %args ) = validated_setter(
81 \@_,
82 value => { isa => 'Num' },
83 );
84  
85  
86 # Make sure that source is not out of range
87 # The instrument does not complain in any way the value is outside the range
88 1 my $range = $self->cached_source_range();
89 1 ▶ if (abs($value) > $range * 1.00001) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $value > $range * "1.00001") 0 1 1
90 0 croak "Source level $value is beyond the current source range $range";
91 }
92
93 1 return $self->linear_step_sweep(
94 to => $value, verbose => $self->verbose,
95 %args
96 );
97 }
98  
99  
100 0 ▶sub get_measurement {
Subroutine get_measurement: not called CC=1 SCAR=6.9
Pod documented
101 0 my ( $self, %args ) = validated_getter( \@_ );
102 0 my $meas = $self->query( command => ':MEAS?', %args );
103 0 my $elements = $self->query( command => ':FORM:ELEM:SENS?' );
104 0 my @elements = split /,/, $elements;
105 0 my @meas_values = split /,/, $meas;
106 0 my %result = map { $_ => shift @meas_values } @elements;
107 0 return \%result;
108 }
109  
110 #
111 # Aliases for Lab::XPRESS::Sweep API
112 #
113  
114  
115 1 ▶sub cached_level {
Subroutine cached_level: called CC=1 SCAR=0.0
Pod documented
116 1 my $self = shift;
117 1 return $self->cached_source_level(@_);
118 }
119  
120  
121 1 ▶sub get_level {
Subroutine get_level: called CC=1 SCAR=0.0
Pod documented
122 1 my $self = shift;
123 1 return $self->source_level_query(@_);
124 }
125  
126  
127 0 ▶sub set_voltage {
Subroutine set_voltage: not called CC=1 SCAR=6.9
Pod documented
128 0 my $self = shift;
129 0 my $value = shift;
130 0 return $self->set_level( value => $value );
131 }
132  
133 2 with qw(
134 Lab::Moose::Instrument::Common
135 Lab::Moose::Instrument::SCPI::Sense::Function::Concurrent
136 Lab::Moose::Instrument::SCPI::Sense::Protection
137 Lab::Moose::Instrument::SCPI::Sense::Range
138 Lab::Moose::Instrument::SCPI::Sense::NPLC
139 Lab::Moose::Instrument::SCPI::Source::Function
140 Lab::Moose::Instrument::SCPI::Source::Level
141 Lab::Moose::Instrument::SCPI::Source::Range
142 Lab::Moose::Instrument::LinearStepSweep
143 );
144  
145 17 ▶after source_level => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
146 17 my $self = shift;
147  
148 # B2901A (with GPIB) accepts "SOUR:VOLT:LEV" in a faster rate than
149 # it can set the value. Slow it down by doing a query after each set.
150 17 $self->source_level_query();
151 2 };
152  
153 2 __PACKAGE__->meta()->make_immutable();
154  
155 2 1;
156  
157 __END__
« Moose/Instrument/OI_ILM210.pm ↑ Summary Moose/Instrument/RS_ZVM.pm »