| 1 | package Lab::Instrument::SR830::AuxOut; | ||
| 2 | #ABSTRACT: Aux Outputs of the Stanford Research SR830 Lock-In Amplifier | ||
| 3 | $Lab::Instrument::SR830::AuxOut::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | |||
| 7 | use warnings; | ||
| 8 | use strict; | ||
| 9 | |||
| 10 | |||
| 11 | use Lab::Instrument; | ||
| 12 | use Data::Dumper; | ||
| 13 | use Carp; | ||
| 14 | |||
| 15 | use parent qw/Lab::Instrument::Source/; | ||
| 16 | |||
| 17 | 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 | my $proto = shift; | ||
| 47 | my $class = ref($proto) || $proto; | ||
| 48 | my $self = $class->SUPER::new(@_); | ||
| 49 | $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); | ||
| 50 | $self->empty_buffer(); | ||
| 51 | my $channel = $self->channel; | ||
| 52 | if ( not defined $channel ) { | ||
| 53 | croak "need channel (1-4) in constructor for ", __PACKAGE__; | ||
| 54 | } | ||
| 55 | elsif ( $channel !~ /^[1-4]$/ ) { | ||
| 56 | croak "channel '$channel' is not in the range (1..4)"; | ||
| 57 | } | ||
| 58 | return $self; | ||
| 59 | } | ||
| 60 | |||
| 61 | sub empty_buffer { | ||
| 62 | my $self = shift; | ||
| 63 | my ($times) = $self->_check_args( \@_, ['times'] ); | ||
| 64 | if ($times) { | ||
| 65 | for ( my $i = 0; $i < $times; $i++ ) { | ||
| 66 | eval { $self->read( brutal => 1 ) }; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | else { | ||
| 70 | while ( $self->read( brutal => 1 ) ) { | ||
| 71 | print "Cleaning buffer."; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | sub _set_level { | ||
| 78 | my $self = shift; | ||
| 79 | my ( $value, $tail ) = $self->_check_args( \@_, ['value'] ); | ||
| 80 | |||
| 81 | if ( abs($value) > 10.5 ) { | ||
| 82 | Lab::Exception::CorruptParameter->throw( | ||
| 83 | "The desired source level $value is not within the source range (10.5 V) \n" | ||
| 84 | ); | ||
| 85 | } | ||
| 86 | |||
| 87 | my $cmd = sprintf( "AUXV %d, %ee", $self->{channel}, $value ); | ||
| 88 | |||
| 89 | $self->write( $cmd, { error_check => 1 }, $tail ); | ||
| 90 | |||
| 91 | return $value; | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | sub set_voltage { | ||
| 96 | my $self = shift; | ||
| 97 | my ( $voltage, $tail ) = $self->_check_args( \@_, ['voltage'] ); | ||
| 98 | |||
| 99 | return $self->set_level( $voltage, $tail ); | ||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | sub get_level { | ||
| 104 | my $self = shift; | ||
| 105 | my ($tail) = $self->_check_args( \@_, [] ); | ||
| 106 | my $channel = $self->channel; | ||
| 107 | return $self->query( "AUXV? $channel", $tail ); | ||
| 108 | } | ||
| 109 | |||
| 110 | sub active { | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | |||
| 114 | 1; | ||
| 115 | |||
| 116 | __END__ |