File Coverage

blib/lib/Lab/Moose/Instrument/Keithley2450.pm
Criterion Covered Total %
statement 20 50 40.0
branch 0 8 0.0
condition n/a
subroutine 7 15 46.6
pod 7 8 87.5
total 34 81 41.9


line stmt bran cond sub pod time code
1             package Lab::Moose::Instrument::Keithley2450;
2             $Lab::Moose::Instrument::Keithley2450::VERSION = '3.880';
3             #ABSTRACT: Keithley 2450 voltage/current sourcemeter.
4              
5 1     1   2708 use v5.20;
  1         4  
6              
7 1     1   7 use Moose;
  1         3  
  1         8  
8 1     1   7741 use MooseX::Params::Validate;
  1         3  
  1         10  
9             use Lab::Moose::Instrument
10 1     1   548 qw/validated_getter validated_setter setter_params/;
  1         2  
  1         73  
11 1     1   7 use Lab::Moose::Instrument::Cache;
  1         3  
  1         11  
12 1     1   687 use Carp;
  1         3  
  1         64  
13 1     1   7 use namespace::autoclean;
  1         3  
  1         11  
14              
15             extends 'Lab::Moose::Instrument';
16              
17             around default_connection_options => sub {
18             my $orig = shift;
19             my $self = shift;
20             my $options = $self->$orig();
21             my $usb_opts = { vid => 0x05e6, pid => 0x2450 }; # FIXME
22             $options->{USB} = $usb_opts;
23             $options->{'VISA::USB'} = $usb_opts;
24             return $options;
25             };
26              
27             has [qw/max_units_per_second max_units_per_step min_units max_units/] =>
28             ( is => 'ro', isa => 'Num', required => 1 );
29              
30             has source_level_timestamp => (
31             is => 'rw',
32             isa => 'Num',
33             init_arg => undef,
34             );
35              
36             has verbose => (
37             is => 'ro',
38             isa => 'Bool',
39             default => 1
40             );
41              
42             sub BUILD {
43 0     0 0   my $self = shift;
44              
45 0           $self->clear();
46 0           $self->cls();
47             }
48              
49              
50              
51             sub set_level {
52 0     0 1   my ( $self, $value, %args ) = validated_setter(
53             \@_,
54             value => { isa => 'Num' },
55             );
56              
57 0           return $self->linear_step_sweep(
58             to => $value, verbose => $self->verbose,
59             %args
60             );
61             }
62              
63              
64             sub get_value {
65 0     0 1   my ( $self, %args ) = validated_getter( \@_ );
66 0           return $self->query( command => 'READ?', %args );
67             }
68              
69              
70             sub source_limit {
71 0     0 1   my ( $self, $value, %args ) = validated_setter(
72             \@_,
73             value => { isa => 'Num' },
74             );
75 0           my $func = $self->cached_source_function();
76 0           my $lim_func;
77              
78 0 0         if ( $func eq 'VOLT' ) {
    0          
79 0           $lim_func = 'I';
80             }
81             elsif ( $func eq 'CURR' ) {
82 0           $lim_func = 'V';
83             }
84             else {
85 0           croak("unknown source function $func (must one of VOLT or CURR)");
86             }
87 0           $self->write( command => "SOUR:${func}:${lim_func}LIM $value", %args );
88             }
89              
90             sub source_limit_query {
91 0     0 1   my ( $self, %args ) = validated_getter( \@_ );
92              
93 0           my $func = $self->cached_source_function();
94 0           my $lim_func;
95              
96 0 0         if ( $func eq 'VOLT' ) {
    0          
97 0           $lim_func = 'I';
98             }
99             elsif ( $func eq 'CURR' ) {
100 0           $lim_func = 'V';
101             }
102             else {
103 0           croak("unknown source function $func (must one of VOLT or CURR)");
104             }
105 0           return $self->query( command => "SOUR:${func}:${lim_func}LIM?", %args );
106             }
107              
108             #
109             # Aliases for Lab::XPRESS::Sweep API
110             #
111              
112              
113             sub cached_level {
114 0     0 1   my $self = shift;
115 0           return $self->cached_source_level(@_);
116             }
117              
118              
119             sub get_level {
120 0     0 1   my $self = shift;
121 0           return $self->source_level_query(@_);
122             }
123              
124              
125             sub set_voltage {
126 0     0 1   my $self = shift;
127 0           my $value = shift;
128 0           return $self->set_level( value => $value );
129             }
130              
131             with qw(
132             Lab::Moose::Instrument::Common
133             Lab::Moose::Instrument::SCPI::Output::State
134             Lab::Moose::Instrument::SCPI::Sense::Function
135             Lab::Moose::Instrument::SCPI::Sense::Range
136             Lab::Moose::Instrument::SCPI::Sense::NPLC
137             Lab::Moose::Instrument::SCPI::Source::Function
138             Lab::Moose::Instrument::SCPI::Source::Level
139             Lab::Moose::Instrument::SCPI::Source::Range
140             Lab::Moose::Instrument::LinearStepSweep
141             );
142              
143             __PACKAGE__->meta()->make_immutable();
144              
145             1;
146              
147             __END__
148              
149             =pod
150              
151             =encoding UTF-8
152              
153             =head1 NAME
154              
155             Lab::Moose::Instrument::Keithley2450 - Keithley 2450 voltage/current sourcemeter.
156              
157             =head1 VERSION
158              
159             version 3.880
160              
161             =head1 SYNOPSIS
162              
163             use Lab::Moose;
164              
165             my $smu = instrument(
166             type => 'Keithley2450',
167             connection_type => 'LinuxGPIB',
168             connection_options => {gpib_address => 15},
169             # mandatory protection settings
170             max_units_per_step => 0.001, # max step is 1mV/1mA
171             max_units_per_second => 0.01,
172             min_units => -10,
173             max_units => 10,
174             );
175              
176             ### Sourcing
177              
178              
179             # Source voltage
180             $smu->source_function(value => 'VOLT');
181             $smu->source_range(value => 210);
182            
183             # Step-sweep to new level.
184             # Stepsize and speed is given by (max|min)_units* settings.
185             $smu->set_level(value => 9);
186              
187             # Get current level from device cache (without sending a query to the
188             # instrument):
189             my $level = $smu->cached_level();
190              
191             ### Measurement
192              
193             # Measure current
194             $smu->sense_function(value => 'CURR');
195             $smu->sense_nplc(value => 2);
196              
197             # Get value of current
198             my $current = $smu->get_value();
199              
200             =head1 METHODS
201              
202             Used roles:
203              
204             =over
205              
206             =item L<Lab::Moose::Instrument::Common>
207              
208             =item L<Lab::Moose::Instrument::SCPI::Output::State>
209              
210             =item L<Lab::Moose::Instrument::SCPI::Sense::Range>
211              
212             =item L<Lab::Moose::Instrument::SCPI::Sense::NPLC>
213              
214             =item L<Lab::Moose::Instrument::SCPI::Source::Function>
215              
216             =item L<Lab::Moose::Instrument::SCPI::Source::Level>
217              
218             =item L<Lab::Moose::Instrument::SCPI::Source::Range>
219              
220             =item L<Lab::Moose::Instrument::LinearStepSweep>
221              
222             =back
223              
224             =head2 set_level
225              
226             $smu->set_level(value => $new_level);
227              
228             Go to new level. Sweep with multiple steps if the distance between current and
229             new level is larger than C<max_units_per_step>.
230              
231             =head2 get_value
232              
233             my $value = $smu->get_value();
234              
235             Perform measurement of value defined by C<sense_function>.
236              
237             =head2 source_limit/source_limit_query
238              
239             Set current compliance limit of voltage source to 1mA
240              
241             $smu->source_function(value => 'VOLT');
242             $smu->source_limit(value => 1e-3);
243              
244             Set voltage compliance limit of current source to 1V
245              
246             $smu->source_function(value => 'CURR');
247             $smu->source_limit(value => 1);
248              
249             Get current source limit
250             my $limit = $smu->source_limit_query();
251              
252             =head2 cached_level
253              
254             my $current_level = $smu->cached_level();
255              
256             Get current value from device cache.
257              
258             =head2 get_level
259              
260             my $current_level = $smu->get_level();
261              
262             Query current level.
263              
264             =head2 set_voltage
265              
266             $smu->set_voltage($value);
267              
268             For XPRESS voltage sweep. Equivalent to C<< set_level(value => $value) >>.
269              
270             =head1 COPYRIGHT AND LICENSE
271              
272             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
273              
274             Copyright 2021 Simon Reinhardt
275              
276              
277             This is free software; you can redistribute it and/or modify it under
278             the same terms as the Perl 5 programming language system itself.
279              
280             =cut