| 1 | package Lab::Moose::Instrument::YokogawaGS200; | ||||||||||
| 2 | 2 | $Lab::Moose::Instrument::YokogawaGS200::VERSION = '3.931'; | |||||||||
| 3 | #ABSTRACT: YokogawaGS200 voltage/current source. | ||||||||||
| 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 | 1 | ▶ | around default_connection_options => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | my $orig = shift; | |||||||||
| 20 | 1 | my $self = shift; | |||||||||
| 21 | 1 | my $options = $self->$orig(); | |||||||||
| 22 | 1 | my $usb_opts = { vid => 0x0b21, pid => 0x0039 }; | |||||||||
| 23 | 1 | $options->{USB} = $usb_opts; | |||||||||
| 24 | 1 | $options->{'VISA::USB'} = $usb_opts; | |||||||||
| 25 | 1 | return $options; | |||||||||
| 26 | 2 | }; | |||||||||
| 27 | |||||||||||
| 28 | 2 | has [qw/max_units_per_second max_units_per_step min_units max_units/] => | |||||||||
| 29 | ( is => 'ro', isa => 'Num', required => 1 ); | ||||||||||
| 30 | |||||||||||
| 31 | 2 | has source_level_timestamp => ( | |||||||||
| 32 | is => 'rw', | ||||||||||
| 33 | isa => 'Num', | ||||||||||
| 34 | init_arg => undef, | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 2 | has verbose => ( | |||||||||
| 38 | is => 'ro', | ||||||||||
| 39 | isa => 'Bool', | ||||||||||
| 40 | default => 1 | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | 1 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||
| 44 | 1 | my $self = shift; | |||||||||
| 45 | |||||||||||
| 46 | # | ||||||||||
| 47 | |||||||||||
| 48 | # with USB-TMC, clear results in this error: | ||||||||||
| 49 | # error in libusb_control_transfer_write: Pipe error at /home/simon/.plenv/versions/5.24.0/lib/perl5/site_perl/5.24.0/x86_64-linux/USB/LibUSB/Device/Handle.pm line 22. | ||||||||||
| 50 | # apparently in USB::TMC::clear_feature_endpoint_out | ||||||||||
| 51 | 1 | ▶ | if ( $self->connection_type eq 'USB' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | $self->clear( yoko => 1 ); | |||||||||
| 53 | } | ||||||||||
| 54 | else { | ||||||||||
| 55 | 1 | $self->clear(); | |||||||||
| 56 | } | ||||||||||
| 57 | 1 | $self->cls(); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | # The Source:Range commands are NOT SCPI compliant, as they do not include | ||||||||||
| 62 | # the Source:Function, like in SOUR:VOLT:RANG | ||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | 2 | cache source_range => ( getter => 'source_range_query' ); | |||||||||
| 66 | |||||||||||
| 67 | 4 | ▶ | sub source_range_query { | ||||||||
|
Subroutine
source_range_query: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 68 | 4 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||
| 69 | |||||||||||
| 70 | 4 | return $self->cached_source_range( | |||||||||
| 71 | $self->query( command => "SOUR:RANG?", %args ) ); | ||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 4 | ▶ | sub source_range { | ||||||||
|
Subroutine
source_range: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 75 | 4 | my ( $self, $value, %args ) = validated_setter( | |||||||||
| 76 | \@_, | ||||||||||
| 77 | ); | ||||||||||
| 78 | |||||||||||
| 79 | 4 | $self->write( command => "SOUR:RANG $value", %args ); | |||||||||
| 80 | |||||||||||
| 81 | 4 | $self->cached_source_range($value); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 2 | cache source_level => ( getter => 'source_level_query' ); | |||||||||
| 85 | |||||||||||
| 86 | 4 | ▶ | sub source_level_query { | ||||||||
|
Subroutine
source_level_query: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 87 | 4 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||
| 88 | |||||||||||
| 89 | 4 | return $self->cached_source_level( | |||||||||
| 90 | $self->query( command => ":SOUR:LEV?", %args ) ); | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 17 | ▶ | sub source_level { | ||||||||
|
Subroutine
source_level: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 94 | 17 | my ( $self, $value, %args ) = validated_setter( | |||||||||
| 95 | \@_, | ||||||||||
| 96 | value => { isa => 'Num' } | ||||||||||
| 97 | ); | ||||||||||
| 98 | |||||||||||
| 99 | 17 | $self->write( | |||||||||
| 100 | command => sprintf( "SOUR:LEV %.15g", $value ), | ||||||||||
| 101 | %args | ||||||||||
| 102 | ); | ||||||||||
| 103 | 17 | $self->cached_source_level($value); | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | |||||||||||
| 107 | 1 | ▶ | sub set_level { | ||||||||
|
Subroutine
set_level: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 108 | 1 | my ( $self, $value, %args ) = validated_setter( | |||||||||
| 109 | \@_, | ||||||||||
| 110 | value => { isa => 'Num' }, | ||||||||||
| 111 | ); | ||||||||||
| 112 | |||||||||||
| 113 | 1 | return $self->linear_step_sweep( | |||||||||
| 114 | to => $value, verbose => $self->verbose, | ||||||||||
| 115 | %args | ||||||||||
| 116 | ); | ||||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | # | ||||||||||
| 120 | # Aliases for Lab::XPRESS::Sweep API | ||||||||||
| 121 | # | ||||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | 1 | ▶ | sub cached_level { | ||||||||
|
Subroutine
cached_level: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 125 | 1 | my $self = shift; | |||||||||
| 126 | 1 | return $self->cached_source_level(@_); | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | |||||||||||
| 130 | 1 | ▶ | sub get_level { | ||||||||
|
Subroutine
get_level: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 131 | 1 | my $self = shift; | |||||||||
| 132 | 1 | return $self->source_level_query(@_); | |||||||||
| 133 | } | ||||||||||
| 134 | |||||||||||
| 135 | |||||||||||
| 136 | 0 | ▶ | sub set_voltage { | ||||||||
|
Subroutine
set_voltage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 137 | 0 | my $self = shift; | |||||||||
| 138 | 0 | my $value = shift; | |||||||||
| 139 | 0 | return $self->set_level( value => $value ); | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 0 | ▶ | sub config_sweep { | ||||||||
|
Subroutine
config_sweep: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 143 | 0 | my ( $self, %args ) = validated_getter( | |||||||||
| 144 | \@_, | ||||||||||
| 145 | point => { isa => 'Num' }, | ||||||||||
| 146 | rate => { isa => 'Num' }, | ||||||||||
| 147 | ); | ||||||||||
| 148 | |||||||||||
| 149 | 0 | my $target = delete $args{point}; | |||||||||
| 150 | 0 | my $rate = delete $args{rate}; | |||||||||
| 151 | |||||||||||
| 152 | 0 | $self->cls(%args); | |||||||||
| 153 | |||||||||||
| 154 | # Enforce limits | ||||||||||
| 155 | 0 | $self->check_max_and_min($target); | |||||||||
| 156 | 0 | my $max_rate = $self->max_units_per_second; | |||||||||
| 157 | 0 | ▶ | if ( $rate > $max_rate ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | 0 | croak "Sweep rate $rate exceeds max_untis_per_second ($max_rate)"; | |||||||||
| 159 | } | ||||||||||
| 160 | |||||||||||
| 161 | 0 | my $current_level = $self->get_level(); | |||||||||
| 162 | 0 | my $time = abs( ( $target - $current_level ) / $rate ); | |||||||||
| 163 | 0 | ▶ | if ( $time < 0.1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 164 | 0 | carp "sweep time < 0.1 seconds; adjusting to 0.1 seconds"; | |||||||||
| 165 | 0 | $time = 0.1; | |||||||||
| 166 | } | ||||||||||
| 167 | 0 | ▶ | if ( $time > 3600 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 168 | 0 | croak "sweep time needs to be <= 3600 seconds"; | |||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | 0 | $self->write( command => 'PROG:REP 0', %args ); | |||||||||
| 172 | 0 | $self->write( command => sprintf( 'PROG:INT %.17g', $time ), %args ); | |||||||||
| 173 | 0 | $self->write( command => sprintf( 'PROG:SLOP %.17g', $time ), %args ); | |||||||||
| 174 | |||||||||||
| 175 | 0 | $self->write( command => 'PROG:EDIT:STAR', %args ); | |||||||||
| 176 | |||||||||||
| 177 | # do not use 'source_level', no caching needed here | ||||||||||
| 178 | 0 | $self->write( command => sprintf( "SOUR:LEV %.15g", $target ), %args ); | |||||||||
| 179 | 0 | $self->write( command => 'PROG:EDIT:END', %args ); | |||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | 0 | ▶ | sub wait { | ||||||||
|
Subroutine
wait: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 183 | 0 | my ( $self, %args ) = validated_getter( | |||||||||
| 184 | \@_, | ||||||||||
| 185 | ); | ||||||||||
| 186 | 0 | my $verbose = $self->verbose; | |||||||||
| 187 | 0 | my $autoflush = STDOUT->autoflush(); | |||||||||
| 188 | |||||||||||
| 189 | 0 | while (1) { | |||||||||
| 190 | 0 | ▶ | if ($verbose) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 191 | 0 | my $level = $self->get_level(%args); | |||||||||
| 192 | 0 | printf( "Level: %.5e \r", $level ); | |||||||||
| 193 | } | ||||||||||
| 194 | 0 | ▶ | if ( not $self->active(%args) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 195 | 0 | last; | |||||||||
| 196 | } | ||||||||||
| 197 | } | ||||||||||
| 198 | |||||||||||
| 199 | 0 | ▶ | if ($verbose) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 200 | 0 | print " " x 70 . "\r"; | |||||||||
| 201 | } | ||||||||||
| 202 | |||||||||||
| 203 | # reset autoflush to previous value | ||||||||||
| 204 | 0 | STDOUT->autoflush($autoflush); | |||||||||
| 205 | |||||||||||
| 206 | } | ||||||||||
| 207 | |||||||||||
| 208 | 0 | ▶ | sub active { | ||||||||
|
Subroutine
active: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 209 | 0 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||
| 210 | |||||||||||
| 211 | # Set EOP (end of program) bit in Extended Event Enable Register | ||||||||||
| 212 | 0 | $self->write( command => 'STAT:ENAB 128', %args ); | |||||||||
| 213 | |||||||||||
| 214 | 0 | my $status = $self->get_status(%args); | |||||||||
| 215 | 0 | ▶ | if ( $status->{'EES'} == 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 216 | 0 | return 0; | |||||||||
| 217 | } | ||||||||||
| 218 | 0 | return 1; | |||||||||
| 219 | } | ||||||||||
| 220 | |||||||||||
| 221 | # return hashref | ||||||||||
| 222 | 0 | ▶ | sub get_status { | ||||||||
|
Subroutine
get_status: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 223 | 0 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||
| 224 | |||||||||||
| 225 | 0 | my $status = int( $self->query( command => '*STB?', %args ) ); | |||||||||
| 226 | 0 | my @flags = qw/NONE EES ESB MAX NONE EAV MSS NONE/; | |||||||||
| 227 | 0 | my $result = {}; | |||||||||
| 228 | 0 | for my $i ( 0 .. 7 ) { | |||||||||
| 229 | 0 | my $flag = $flags[$i]; | |||||||||
| 230 | 0 | $result->{$flag} = $status & 1; | |||||||||
| 231 | 0 | $status >>= 1; | |||||||||
| 232 | } | ||||||||||
| 233 | 0 | return $result; | |||||||||
| 234 | } | ||||||||||
| 235 | |||||||||||
| 236 | 0 | ▶ | sub trg { | ||||||||
|
Subroutine
trg: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 237 | 0 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||
| 238 | 0 | my $output = $self->query( command => 'OUTP:STAT?', %args ); | |||||||||
| 239 | 0 | ▶ | if ( $output == 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 240 | 0 | croak "output needs to be on before running a program"; | |||||||||
| 241 | } | ||||||||||
| 242 | 0 | $self->write( command => 'PROG:RUN' ); | |||||||||
| 243 | } | ||||||||||
| 244 | |||||||||||
| 245 | |||||||||||
| 246 | 0 | ▶ | sub sweep_to_level { | ||||||||
|
Subroutine
sweep_to_level: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 247 | 0 | my ( $self, %args ) = validated_getter( | |||||||||
| 248 | \@_, | ||||||||||
| 249 | target => { isa => 'Num' }, | ||||||||||
| 250 | rate => { isa => 'Num' } | ||||||||||
| 251 | ); | ||||||||||
| 252 | |||||||||||
| 253 | 0 | my $target = delete $args{target}; | |||||||||
| 254 | 0 | my $rate = delete $args{rate}; | |||||||||
| 255 | |||||||||||
| 256 | 0 | $self->config_sweep( point => $target, rate => $rate, %args ); | |||||||||
| 257 | 0 | $self->trg(%args); | |||||||||
| 258 | 0 | $self->wait(%args); | |||||||||
| 259 | } | ||||||||||
| 260 | |||||||||||
| 261 | 2 | with qw( | |||||||||
| 262 | Lab::Moose::Instrument::Common | ||||||||||
| 263 | Lab::Moose::Instrument::SCPI::Source::Function | ||||||||||
| 264 | Lab::Moose::Instrument::LinearStepSweep | ||||||||||
| 265 | ); | ||||||||||
| 266 | |||||||||||
| 267 | 2 | __PACKAGE__->meta()->make_immutable(); | |||||||||
| 268 | |||||||||||
| 269 | 2 | 1; | |||||||||
| 270 | |||||||||||
| 271 | __END__ | ||||||||||