File Coverage

blib/lib/Lab/Moose/Instrument/KeysightE3633E.pm
Criterion Covered Total %
statement 23 49 46.9
branch n/a
condition n/a
subroutine 8 18 44.4
pod 7 10 70.0
total 38 77 49.3


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