Instrument/SR830/AuxOut.pm

filter: Statementstmt 70.1% 40 / 57 Branchbran 33.3% 4 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 76.9% 10 / 13 Podpod 60.0% 3 / 5 totaltotal 63.0% 58 / 92 SCAR 24.3
CC
8
Cov
62%
empty_buffer
7.0
_set_level
6.0
new
4.6
CRAP 11.4
« Moose/Connection/VISA/USB.pm ↑ Summary Connection/Mock.pm »
1 package Lab::Instrument::SR830::AuxOut;
2 #ABSTRACT: Aux Outputs of the Stanford Research SR830 Lock-In Amplifier
3 2 $Lab::Instrument::SR830::AuxOut::VERSION = '3.881';
4 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 2 ▶use Lab::Instrument;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use parent qw/Lab::Instrument::Source/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 our %fields = (
18 supported_connections => [ 'GPIB', 'VISA' ],
19  
20 # default settings for the supported connections
21 connection_settings => {
22 gpib_board => 0,
23 gpib_address => undef,
24 timeout => 1
25 },
26  
27 device_settings => {
28 gate_protect => 1,
29  
30 #gp_equal_level => 1e-5,
31 gp_max_units_per_second => 0.005,
32 gp_max_units_per_step => 0.001,
33 gp_max_step_per_second => 5,
34  
35 max_sweep_time => 3600,
36 min_sweep_time => 0.1,
37  
38 stepsize => 0.01,
39  
40 },
41  
42 channel => undef,
43 );
44  
45 sub new {
46 2 ▶ my $proto = shift;
Subroutine new: called CC=4 SCAR=15.2
Pod documented
47 2 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
48 2 my $self = $class->SUPER::new(@_);
49 2 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
50 2 $self->empty_buffer();
51 2 my $channel = $self->channel;
52 2 ▶ if ( not defined $channel ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $channel) { } 0 2 2
elsif (not $channel =~ /^[1-4]$/u) { } 0 2 2
53 0 croak "need channel (1-4) in constructor for ", __PACKAGE__;
54 }
55 elsif ( $channel !~ /^[1-4]$/ ) {
56 0 croak "channel '$channel' is not in the range (1..4)";
57 }
58 2 return $self;
59 }
60  
61 sub empty_buffer {
62 2 ▶ my $self = shift;
Subroutine empty_buffer: called CC=4 SCAR=19.4
Pod undocumented
63 2 my ($times) = $self->_check_args( \@_, ['times'] );
64 2 ▶ if ($times) {
Branch: 1 branch
BranchTrueFalseTotal
if ($times) { } 0 2 2
65 0 ▶ for ( my $i = 0; $i < $times; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $times) 0 0 0
66 0 eval { $self->read( brutal => 1 ) };
67 }
68 }
69 else {
70 2 ▶ while ( $self->read( brutal => 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->read("brutal", 1)) 0 2 2
71 0 print "Cleaning buffer.";
72 }
73 }
74 }
75  
76  
77 sub _set_level {
78 0 ▶ my $self = shift;
Subroutine _set_level: not called CC=2 SCAR=17.9
79 0 my ( $value, $tail ) = $self->_check_args( \@_, ['value'] );
80  
81 0 ▶ if ( abs($value) > 10.5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $value > "10.5") 0 0 0
82 0 Lab::Exception::CorruptParameter->throw(
83 "The desired source level $value is not within the source range (10.5 V) \n"
84 );
85 }
86  
87 0 my $cmd = sprintf( "AUXV %d, %ee", $self->{channel}, $value );
88  
89 0 $self->write( $cmd, { error_check => 1 }, $tail );
90  
91 0 return $value;
92 }
93  
94  
95 sub set_voltage {
96 0 ▶ my $self = shift;
Subroutine set_voltage: not called CC=1 SCAR=6.9
Pod documented
97 0 my ( $voltage, $tail ) = $self->_check_args( \@_, ['voltage'] );
98  
99 0 return $self->set_level( $voltage, $tail );
100 }
101  
102  
103 sub get_level {
104 6 ▶ my $self = shift;
Subroutine get_level: called CC=1 SCAR=0.0
Pod documented
105 6 my ($tail) = $self->_check_args( \@_, [] );
106 6 my $channel = $self->channel;
107 6 return $self->query( "AUXV? $channel", $tail );
108 }
109  
110 sub active {
111 0 ▶ return 0;
Subroutine active: not called CC=1 SCAR=6.9
Pod undocumented
112 }
113  
114 2 1;
115  
116 __END__
117  
118 =pod
119  
120 =encoding UTF-8
121  
122 =head1 NAME
123  
124 Lab::Instrument::SR830::AuxOut - Aux Outputs of the Stanford Research SR830 Lock-In Amplifier
125  
126 =head1 VERSION
127  
128 version 3.881
129  
130 =head1 SYNOPSIS
131  
132 use Lab::Instrument::SR830::AuxOut
133 my $output = Lab::Instrument::SR830::AuxOut->new(%options, channel => 1);
134  
135 =head1 DESCRIPTION
136  
137 This class provides access to the four DC outputs of the SR830. You have to
138 provide a C<channel> (1..4) parameter in the constructor.
139  
140 B<To use multiple virtual instruments, which use the same physical device, you have to share the connection between the virtual instruments:>
141  
142 use Lab::Measurement;
143  
144 # Create the shared connection.
145 my $connection = Connection('LinuxGPIB', {gpib_address => 8});
146
147 # Create two outputs.
148 my $gate = Instrument('SR830::AuxOut', {connection => $connection,
149 channel => 1,
150 gate_protect => 0});
151 my $bias = Instrument('SR830::AuxOut', {connection => $connection,
152 channel => 2,
153 gate_protect => 0});
154  
155 You can now use C<$gate> and C<$bias> to build XPRESS L<Voltage
156 Sweeps|Lab::XPRESS::Sweep::Voltage>. The SR830 does not have hardware support
157 for continuous voltage sweeps. Thus, the C<mode> parameter of the sweep must be
158 set to C<'step'> or C<'list'> and the C<jump> parameter must be set to
159 C<1>. Example sweep configuration:
160  
161 my $gate_sweep = Sweep('Voltage',
162 {
163 mode => 'step',
164 instrument => $gate,
165 points => [-0.1,0.1],
166 stepwidth => [0.001],
167 jump => 1,
168 rate => [0.001],
169
170 });
171
172 my $bias_sweep = Sweep('Voltage',
173 {
174 mode => 'step',
175 instrument => $bias,
176 points => [-0.1,0.1],
177 stepwidth => [0.001],
178 rate => [0.001],
179 jump => 1,
180 });
181  
182 =head1 Methods
183  
184 =head2 _set_level($voltage)
185  
186 Set the output voltage. Will throw an exception, if the absolute value of
187 C<$voltage> is bigger than 10.5 V.
188  
189 =head2 set_voltage($voltage)
190  
191 Equivalent to C<_set_level>.
192  
193 =head2 set_level($voltage)
194  
195 See L<Lab::Instrument::Source>.
196  
197 =head2 get_level()
198  
199 Query the current output voltage.
200  
201 =head1 COPYRIGHT AND LICENSE
202  
203 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
204  
205 Copyright 2016 Simon Reinhardt
206 2017 Andreas K. Huettel
207 2020 Andreas K. Huettel
208  
209  
210 This is free software; you can redistribute it and/or modify it under
211 the same terms as the Perl 5 programming language system itself.
212  
213 =cut
« Moose/Connection/VISA/USB.pm ↑ Summary Connection/Mock.pm »