| 1 | package Lab::Moose::Instrument::OI_Mercury::Magnet; | ||||||||||||||||||||
| 2 | 2 | $Lab::Moose::Instrument::OI_Mercury::Magnet::VERSION = '3.931'; | |||||||||||||||||||
| 3 | #ABSTRACT: Oxford Instruments Mercury magnet power supply | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | ▶ | use v5.20; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use Moose::Util::TypeConstraints qw/enum/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use MooseX::Params::Validate 'validated_hash'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use Lab::Moose::Instrument qw/ | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | validated_getter validated_setter setter_params /; | |||||||||||||||||||
| 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 | 2 | ▶ | use YAML::XS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 2 | ▶ | use Lab::Moose::Countdown; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | extends 'Lab::Moose::Instrument'; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 2 | has verbose => ( | |||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||
| 22 | isa => 'Bool', | ||||||||||||||||||||
| 23 | default => 1 | ||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | has magnet => ( | |||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||
| 28 | isa => enum( [qw/X Y Z/] ), | ||||||||||||||||||||
| 29 | default => 'Z' | ||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | has heater_delay => ( | |||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||
| 34 | isa => 'Lab::Moose::PosInt', | ||||||||||||||||||||
| 35 | default => 60 | ||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | has ATOB => ( | |||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||
| 40 | isa => 'Lab::Moose::PosNum', | ||||||||||||||||||||
| 41 | builder => '_build_ATOB', | ||||||||||||||||||||
| 42 | lazy => 1, | ||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 1 | ▶ | sub _build_ATOB { | ||||||||||||||||||
|
Subroutine
_build_ATOB: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | 1 | my $self = shift; | |||||||||||||||||||
| 47 | 1 | my $magnet = $self->magnet(); | |||||||||||||||||||
| 48 | 1 | return $self->oi_getter( cmd => "READ:DEV:GRP${magnet}:PSU:ATOB" ); | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # default connection options: | ||||||||||||||||||||
| 52 | 1 | ▶ | around default_connection_options => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 1 | my $orig = shift; | |||||||||||||||||||
| 54 | 1 | my $self = shift; | |||||||||||||||||||
| 55 | 1 | my $options = $self->$orig(); | |||||||||||||||||||
| 56 | 1 | $options->{Socket}{port} = 7020; | |||||||||||||||||||
| 57 | 1 | $options->{Socket}{timeout} = 10; | |||||||||||||||||||
| 58 | 1 | return $options; | |||||||||||||||||||
| 59 | 2 | }; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 2 | with 'Lab::Moose::Instrument::OI_Common'; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 1 | ▶ | sub get_catalogue { | ||||||||||||||||||
|
Subroutine
get_catalogue: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 65 | 1 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||||||||||||
| 66 | 1 | return $self->oi_getter( cmd => "READ:SYS:CAT", %args ); | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | ▶ | sub get_temperature { | ||||||||||||||||||
|
Subroutine
get_temperature: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 71 | 0 | my ( $self, %args ) = validated_getter( | |||||||||||||||||||
| 72 | \@_, | ||||||||||||||||||||
| 73 | channel => { isa => 'Str', default => 'MB1.T1' } | ||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | return $self->get_temperature_channel(%args); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | sub get_he_level { | ||||||||||||||||||
|
Subroutine
get_he_level: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 81 | 0 | my ( $self, %args ) = validated_getter( | |||||||||||||||||||
| 82 | \@_, | ||||||||||||||||||||
| 83 | channel => { isa => 'Str', default => 'DB5.L1' } | ||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||
| 85 | 0 | my $channel = delete $args{channel}; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | my $rv | |||||||||||||||||||
| 88 | = $self->oi_getter( cmd => "READ:DEV:$channel:LVL:SIG:HEL", %args ); | ||||||||||||||||||||
| 89 | 0 | $rv =~ s/^LEV://; | |||||||||||||||||||
| 90 | 0 | $rv =~ s/%.*$//; | |||||||||||||||||||
| 91 | 0 | return $rv; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | ▶ | sub get_he_level_resistance { | ||||||||||||||||||
|
Subroutine
get_he_level_resistance: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 96 | 0 | my ( $self, %args ) = validated_getter( | |||||||||||||||||||
| 97 | \@_, | ||||||||||||||||||||
| 98 | channel => { isa => 'Str', default => 'DB5.L1' } | ||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||
| 100 | 0 | my $channel = delete $args{channel}; | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 0 | my $res | |||||||||||||||||||
| 103 | = $self->oi_getter( cmd => "READ:DEV:$channel:LVL:SIG:HEL", %args ); | ||||||||||||||||||||
| 104 | 0 | $res =~ s/^.*:RES://; | |||||||||||||||||||
| 105 | 0 | $res =~ s/O$//; | |||||||||||||||||||
| 106 | 0 | return $res; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | sub get_n2_level { | ||||||||||||||||||
|
Subroutine
get_n2_level: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 111 | 0 | my ( $self, %args ) = validated_getter( | |||||||||||||||||||
| 112 | \@_, | ||||||||||||||||||||
| 113 | channel => { isa => 'Str', default => 'DB5.L1' } | ||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||
| 115 | 0 | my $channel = delete $args{channel}; | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | my $level | |||||||||||||||||||
| 118 | = $self->oi_getter( cmd => "READ:DEV:$channel:LVL:SIG:NIT", %args ); | ||||||||||||||||||||
| 119 | 0 | $level =~ s/^.*:LEV://; | |||||||||||||||||||
| 120 | 0 | $level =~ s/%.*$//; | |||||||||||||||||||
| 121 | 0 | return $level; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | ▶ | sub get_n2_level_frequency { | ||||||||||||||||||
|
Subroutine
get_n2_level_frequency: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 126 | 0 | my ( $self, %args ) = validated_getter( | |||||||||||||||||||
| 127 | \@_, | ||||||||||||||||||||
| 128 | channel => { isa => 'Str', default => 'DB5.L1' } | ||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||
| 130 | 0 | my $channel = delete $args{channel}; | |||||||||||||||||||
| 131 | 0 | my $level | |||||||||||||||||||
| 132 | = $self->oi_getter( cmd => "READ:DEV:$channel:LVL:SIG:NIT", %args ); | ||||||||||||||||||||
| 133 | 0 | $level =~ s/^.*:FREQ://; | |||||||||||||||||||
| 134 | 0 | $level =~ s/:.*$//; | |||||||||||||||||||
| 135 | 0 | return $level; | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 0 | ▶ | sub get_n2_level_counter { | ||||||||||||||||||
|
Subroutine
get_n2_level_counter: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 139 | 0 | my ( $self, %args ) = validated_getter( | |||||||||||||||||||
| 140 | \@_, | ||||||||||||||||||||
| 141 | channel => { isa => 'Str', default => 'DB5.L1' } | ||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||
| 143 | 0 | my $channel = delete $args{channel}; | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 0 | my $level | |||||||||||||||||||
| 146 | = $self->oi_getter( cmd => "READ:DEV:$channel:LVL:SIG:NIT", %args ); | ||||||||||||||||||||
| 147 | 0 | $level =~ s/^COUN://; | |||||||||||||||||||
| 148 | 0 | $level =~ s/n:.*$//; | |||||||||||||||||||
| 149 | 0 | return $level; | |||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | # | ||||||||||||||||||||
| 153 | # now follow the core magnet functions | ||||||||||||||||||||
| 154 | # | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 9 | ▶ | sub validated_magnet_getter { | ||||||||||||||||||
|
Subroutine
validated_magnet_getter: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 157 | 9 | my $args_ref = shift; | |||||||||||||||||||
| 158 | 9 | my %extra_args = @_; | |||||||||||||||||||
| 159 | 9 | my ( $self, %args ) = validated_getter( | |||||||||||||||||||
| 160 | $args_ref, | ||||||||||||||||||||
| 161 | channel => { isa => enum( [qw/X Y Z/] ), optional => 1 }, | ||||||||||||||||||||
| 162 | %extra_args, | ||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||
| 164 | 9 | ▶ | my $channel = delete $args{channel} // $self->magnet(); | ||||||||||||||||||
|
Condition33%1/3
delete $args{"channel"} // $self->magnet
MC/DC0%0/2
delete $args{"channel"} // $self->magnet
delete $args{"channel"}
$self->magnet
Truth table33%1/3
A // B
A= delete $args{"channel"}B= $self->magnet
| |||||||||||||||||||||
| 165 | 9 | $channel = "GRP$channel"; | |||||||||||||||||||
| 166 | 9 | return ( $self, $channel, %args ); | |||||||||||||||||||
| 167 | } | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 6 | ▶ | sub validated_magnet_setter { | ||||||||||||||||||
|
Subroutine
validated_magnet_setter: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 170 | 6 | my $args_ref = shift; | |||||||||||||||||||
| 171 | 6 | my %extra_args = @_; | |||||||||||||||||||
| 172 | 6 | my ( $self, $value, %args ) = validated_setter( | |||||||||||||||||||
| 173 | $args_ref, | ||||||||||||||||||||
| 174 | channel => { isa => enum( [qw/X Y Z/] ), optional => 1 }, | ||||||||||||||||||||
| 175 | %extra_args, | ||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | 6 | ▶ | my $channel = delete $args{channel} // $self->magnet(); | ||||||||||||||||||
|
Condition33%1/3
delete $args{"channel"} // $self->magnet
MC/DC0%0/2
delete $args{"channel"} // $self->magnet
delete $args{"channel"}
$self->magnet
Truth table33%1/3
A // B
A= delete $args{"channel"}B= $self->magnet
| |||||||||||||||||||||
| 179 | 6 | $channel = "GRP$channel"; | |||||||||||||||||||
| 180 | 6 | return ( $self, $value, $channel, %args ); | |||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | 2 | ▶ | sub oim_get_current { | ||||||||||||||||||
|
Subroutine
oim_get_current: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 185 | 2 | my ( $self, $channel, %args ) = validated_magnet_getter( \@_ ); | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 2 | my $current | |||||||||||||||||||
| 188 | = $self->oi_getter( cmd => "READ:DEV:$channel:PSU:SIG:CURR", %args ); | ||||||||||||||||||||
| 189 | 2 | $current =~ s/A$//; | |||||||||||||||||||
| 190 | 2 | return $current; | |||||||||||||||||||
| 191 | } | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 0 | ▶ | sub oim_get_persistent_current { | ||||||||||||||||||
|
Subroutine
oim_get_persistent_current: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 195 | 0 | my ( $self, $channel, %args ) = validated_magnet_getter( \@_ ); | |||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | 0 | my $current | |||||||||||||||||||
| 198 | = $self->oi_getter( cmd => "READ:DEV:$channel:PSU:SIG:PCUR", %args ); | ||||||||||||||||||||
| 199 | 0 | $current =~ s/A$//; | |||||||||||||||||||
| 200 | 0 | return $current; | |||||||||||||||||||
| 201 | } | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 1 | ▶ | sub oim_get_field { | ||||||||||||||||||
|
Subroutine
oim_get_field: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 205 | 1 | my $self = shift; | |||||||||||||||||||
| 206 | 1 | my $current = $self->oim_get_current(@_); | |||||||||||||||||||
| 207 | 1 | my $rv = $current / $self->ATOB(); | |||||||||||||||||||
| 208 | 1 | return sprintf( "%.6f", $rv ); | |||||||||||||||||||
| 209 | } | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | 0 | ▶ | sub oim_get_persistent_field { | ||||||||||||||||||
|
Subroutine
oim_get_persistent_field: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 213 | 0 | my $self = shift; | |||||||||||||||||||
| 214 | 0 | my $current = $self->oim_get_persistent_current(@_); | |||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | 0 | my $rv = $current / $self->ATOB(); | |||||||||||||||||||
| 217 | 0 | return sprintf( "%.6f", $rv ); | |||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | 1 | ▶ | sub oim_get_heater { | ||||||||||||||||||
|
Subroutine
oim_get_heater: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 222 | 1 | my ( $self, $channel, %args ) = validated_magnet_getter( \@_ ); | |||||||||||||||||||
| 223 | 1 | return $self->oi_getter( cmd => "READ:DEV:$channel:PSU:SIG:SWHT", %args ); | |||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | 1 | ▶ | sub oim_set_heater { | ||||||||||||||||||
|
Subroutine
oim_set_heater: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 228 | 1 | my ( $self, $value, $channel, %args ) = validated_magnet_setter( | |||||||||||||||||||
| 229 | \@_, | ||||||||||||||||||||
| 230 | value => { isa => enum( [qw/ON OFF/] ) }, | ||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | 1 | return $self->oi_setter( | |||||||||||||||||||
| 234 | cmd => "SET:DEV:$channel:PSU:SIG:SWHT", | ||||||||||||||||||||
| 235 | value => $value, | ||||||||||||||||||||
| 236 | %args | ||||||||||||||||||||
| 237 | ); | ||||||||||||||||||||
| 238 | } | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | 0 | ▶ | sub heater_on { | ||||||||||||||||||
|
Subroutine
heater_on: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 242 | 0 | my $self = shift; | |||||||||||||||||||
| 243 | 0 | $self->oim_set_heater( value => 'ON' ); | |||||||||||||||||||
| 244 | 0 | countdown( $self->heater_delay, "OI Mercury heater ON: " ); | |||||||||||||||||||
| 245 | } | ||||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | 0 | ▶ | sub heater_off { | ||||||||||||||||||
|
Subroutine
heater_off: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 248 | 0 | my $self = shift; | |||||||||||||||||||
| 249 | 0 | $self->oim_set_heater( value => 'OFF' ); | |||||||||||||||||||
| 250 | 0 | countdown( $self->heater_delay(), "OI Mercury heater OFF: " ); | |||||||||||||||||||
| 251 | } | ||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | 0 | ▶ | sub in_persistent_mode { | ||||||||||||||||||
|
Subroutine
in_persistent_mode: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 255 | 0 | my $self = shift; | |||||||||||||||||||
| 256 | 0 | my $rv = $self->oim_get_heater(@_); | |||||||||||||||||||
| 257 | 0 | ▶ | if ( $rv eq 'ON' ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 258 | 0 | return; | |||||||||||||||||||
| 259 | } | ||||||||||||||||||||
| 260 | elsif ( $rv eq 'OFF' ) { | ||||||||||||||||||||
| 261 | 0 | return 1; | |||||||||||||||||||
| 262 | } | ||||||||||||||||||||
| 263 | else { | ||||||||||||||||||||
| 264 | 0 | croak("unknown heater setting $rv"); | |||||||||||||||||||
| 265 | } | ||||||||||||||||||||
| 266 | } | ||||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | 0 | ▶ | sub oim_force_heater { | ||||||||||||||||||
|
Subroutine
oim_force_heater: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 270 | 0 | my ( $self, $value, $channel, %args ) = validated_magnet_setter( | |||||||||||||||||||
| 271 | \@_, | ||||||||||||||||||||
| 272 | value => { isa => enum( [qw/ON OFF/] ) }, | ||||||||||||||||||||
| 273 | ); | ||||||||||||||||||||
| 274 | |||||||||||||||||||||
| 275 | 0 | return $self->oi_setter( | |||||||||||||||||||
| 276 | cmd => "SET:DEV:$channel:PSU:SIG:SWHN", | ||||||||||||||||||||
| 277 | value => $value, %args | ||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||
| 279 | } | ||||||||||||||||||||
| 280 | |||||||||||||||||||||
| 281 | |||||||||||||||||||||
| 282 | 2 | ▶ | sub oim_get_current_sweeprate { | ||||||||||||||||||
|
Subroutine
oim_get_current_sweeprate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 283 | 2 | my ( $self, $channel, %args ) = validated_magnet_getter( \@_ ); | |||||||||||||||||||
| 284 | |||||||||||||||||||||
| 285 | 2 | my $sweeprate | |||||||||||||||||||
| 286 | = $self->oi_getter( cmd => "READ:DEV:$channel:PSU:SIG:RCST", %args ); | ||||||||||||||||||||
| 287 | 2 | $sweeprate =~ s/A\/m$//; | |||||||||||||||||||
| 288 | 2 | return $sweeprate; | |||||||||||||||||||
| 289 | } | ||||||||||||||||||||
| 290 | |||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | 2 | ▶ | sub oim_set_current_sweeprate { | ||||||||||||||||||
|
Subroutine
oim_set_current_sweeprate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 293 | 2 | my ( $self, $value, $channel, %args ) = validated_magnet_setter( \@_ ); | |||||||||||||||||||
| 294 | |||||||||||||||||||||
| 295 | 2 | $value = sprintf( "%.3f", $value ); | |||||||||||||||||||
| 296 | |||||||||||||||||||||
| 297 | 2 | my $rv = $self->oi_setter( | |||||||||||||||||||
| 298 | cmd => "SET:DEV:$channel:PSU:SIG:RCST", | ||||||||||||||||||||
| 299 | value => $value, %args | ||||||||||||||||||||
| 300 | ); | ||||||||||||||||||||
| 301 | |||||||||||||||||||||
| 302 | # this returns amps per minute | ||||||||||||||||||||
| 303 | 2 | $rv =~ s/A\/m$//; | |||||||||||||||||||
| 304 | 2 | return $rv; | |||||||||||||||||||
| 305 | } | ||||||||||||||||||||
| 306 | |||||||||||||||||||||
| 307 | |||||||||||||||||||||
| 308 | 1 | ▶ | sub oim_get_field_sweeprate { | ||||||||||||||||||
|
Subroutine
oim_get_field_sweeprate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 309 | 1 | my $self = shift; | |||||||||||||||||||
| 310 | 1 | my $current_sweeprate = $self->oim_get_current_sweeprate(@_); | |||||||||||||||||||
| 311 | 1 | my $rv = $current_sweeprate / $self->ATOB(); | |||||||||||||||||||
| 312 | 1 | return sprintf( "%.6f", $rv ); | |||||||||||||||||||
| 313 | } | ||||||||||||||||||||
| 314 | |||||||||||||||||||||
| 315 | |||||||||||||||||||||
| 316 | 1 | ▶ | sub oim_set_field_sweeprate { | ||||||||||||||||||
|
Subroutine
oim_set_field_sweeprate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 317 | 1 | my $self = shift; | |||||||||||||||||||
| 318 | 1 | my %args = @_; | |||||||||||||||||||
| 319 | 1 | my $value = delete $args{value}; | |||||||||||||||||||
| 320 | 1 | $value = $value * $self->ATOB(); | |||||||||||||||||||
| 321 | 1 | my $rv = $self->oim_set_current_sweeprate( value => $value, %args ); | |||||||||||||||||||
| 322 | 1 | return $rv / $self->ATOB(); | |||||||||||||||||||
| 323 | } | ||||||||||||||||||||
| 324 | |||||||||||||||||||||
| 325 | |||||||||||||||||||||
| 326 | 1 | ▶ | sub oim_get_activity { | ||||||||||||||||||
|
Subroutine
oim_get_activity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 327 | 1 | my ( $self, $channel, %args ) = validated_magnet_getter( \@_ ); | |||||||||||||||||||
| 328 | 1 | return $self->oi_getter( cmd => "READ:DEV:$channel:PSU:ACTN", %args ); | |||||||||||||||||||
| 329 | } | ||||||||||||||||||||
| 330 | |||||||||||||||||||||
| 331 | |||||||||||||||||||||
| 332 | 1 | ▶ | sub oim_set_activity { | ||||||||||||||||||
|
Subroutine
oim_set_activity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 333 | 1 | my ( $self, $value, $channel, %args ) = validated_magnet_setter( | |||||||||||||||||||
| 334 | \@_, | ||||||||||||||||||||
| 335 | value => { isa => enum( [qw/HOLD RTOS RTOZ CLMP/] ) }, | ||||||||||||||||||||
| 336 | ); | ||||||||||||||||||||
| 337 | 1 | return $self->oi_setter( | |||||||||||||||||||
| 338 | cmd => "SET:DEV:$channel:PSU:ACTN", | ||||||||||||||||||||
| 339 | value => $value, %args | ||||||||||||||||||||
| 340 | ); | ||||||||||||||||||||
| 341 | } | ||||||||||||||||||||
| 342 | |||||||||||||||||||||
| 343 | |||||||||||||||||||||
| 344 | 2 | ▶ | sub oim_set_current_setpoint { | ||||||||||||||||||
|
Subroutine
oim_set_current_setpoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 345 | 2 | my ( $self, $value, $channel, %args ) = validated_magnet_setter( | |||||||||||||||||||
| 346 | \@_, | ||||||||||||||||||||
| 347 | value => { isa => 'Num' }, | ||||||||||||||||||||
| 348 | ); | ||||||||||||||||||||
| 349 | |||||||||||||||||||||
| 350 | 2 | $value = sprintf( "%.4f", $value ); | |||||||||||||||||||
| 351 | |||||||||||||||||||||
| 352 | 2 | my $rv = $self->oi_setter( | |||||||||||||||||||
| 353 | cmd => "SET:DEV:$channel:PSU:SIG:CSET", | ||||||||||||||||||||
| 354 | value => $value, %args | ||||||||||||||||||||
| 355 | ); | ||||||||||||||||||||
| 356 | 2 | $rv =~ s/A$//; | |||||||||||||||||||
| 357 | 2 | return $rv; | |||||||||||||||||||
| 358 | } | ||||||||||||||||||||
| 359 | |||||||||||||||||||||
| 360 | |||||||||||||||||||||
| 361 | 2 | ▶ | sub oim_get_current_setpoint { | ||||||||||||||||||
|
Subroutine
oim_get_current_setpoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 362 | 2 | my ( $self, $channel, %args ) = validated_magnet_getter( \@_ ); | |||||||||||||||||||
| 363 | |||||||||||||||||||||
| 364 | 2 | my $result | |||||||||||||||||||
| 365 | = $self->oi_getter( cmd => "READ:DEV:$channel:PSU:SIG:CSET", %args ); | ||||||||||||||||||||
| 366 | 2 | $result =~ s/A$//; | |||||||||||||||||||
| 367 | 2 | return $result; | |||||||||||||||||||
| 368 | } | ||||||||||||||||||||
| 369 | |||||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | 1 | ▶ | sub oim_set_field_setpoint { | ||||||||||||||||||
|
Subroutine
oim_set_field_setpoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 372 | 1 | my $self = shift; | |||||||||||||||||||
| 373 | 1 | my %args = @_; | |||||||||||||||||||
| 374 | 1 | my $value = delete $args{value}; | |||||||||||||||||||
| 375 | |||||||||||||||||||||
| 376 | 1 | $value = $value * $self->ATOB(); | |||||||||||||||||||
| 377 | |||||||||||||||||||||
| 378 | 1 | my $rv = $self->oim_set_current_setpoint( value => $value, %args ); | |||||||||||||||||||
| 379 | |||||||||||||||||||||
| 380 | 1 | $rv = $rv / $self->ATOB(); | |||||||||||||||||||
| 381 | 1 | return sprintf( "%.6f", $rv ); | |||||||||||||||||||
| 382 | } | ||||||||||||||||||||
| 383 | |||||||||||||||||||||
| 384 | |||||||||||||||||||||
| 385 | 1 | ▶ | sub oim_get_field_setpoint { | ||||||||||||||||||
|
Subroutine
oim_get_field_setpoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 386 | 1 | my $self = shift; | |||||||||||||||||||
| 387 | |||||||||||||||||||||
| 388 | 1 | my $rv = $self->oim_get_current_setpoint(@_); | |||||||||||||||||||
| 389 | |||||||||||||||||||||
| 390 | 1 | return $rv / $self->ATOB(); | |||||||||||||||||||
| 391 | } | ||||||||||||||||||||
| 392 | |||||||||||||||||||||
| 393 | |||||||||||||||||||||
| 394 | 1 | ▶ | sub oim_get_fieldconstant { | ||||||||||||||||||
|
Subroutine
oim_get_fieldconstant: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 395 | 1 | my ( $self, $channel, %args ) = validated_magnet_getter( \@_ ); | |||||||||||||||||||
| 396 | 1 | return $self->oi_getter( cmd => "READ:DEV:$channel:PSU:ATOB", %args ); | |||||||||||||||||||
| 397 | } | ||||||||||||||||||||
| 398 | |||||||||||||||||||||
| 399 | |||||||||||||||||||||
| 400 | 0 | ▶ | sub field_step { | ||||||||||||||||||
|
Subroutine
field_step: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 401 | 0 | my $self = shift; | |||||||||||||||||||
| 402 | 0 | return 1e-4 / $self->oim_get_fieldconstant(@_); | |||||||||||||||||||
| 403 | } | ||||||||||||||||||||
| 404 | |||||||||||||||||||||
| 405 | ############### XPRESS interface ##################### | ||||||||||||||||||||
| 406 | |||||||||||||||||||||
| 407 | 2 | has device_settings => | |||||||||||||||||||
| 408 | ( is => 'ro', isa => 'HashRef', builder => 'build_device_settings' ); | ||||||||||||||||||||
| 409 | |||||||||||||||||||||
| 410 | 2 | has max_field_deviation => ( is => 'ro', isa => 'Num', default => 0.0001 ); | |||||||||||||||||||
| 411 | |||||||||||||||||||||
| 412 | 1 | ▶ | sub build_device_settings { | ||||||||||||||||||
|
Subroutine
build_device_settings: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 413 | return { | ||||||||||||||||||||
| 414 | 1 | has_switchheater => 0, # for now | |||||||||||||||||||
| 415 | }; | ||||||||||||||||||||
| 416 | } | ||||||||||||||||||||
| 417 | |||||||||||||||||||||
| 418 | 0 | ▶ | sub get_field { | ||||||||||||||||||
|
Subroutine
get_field: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 419 | 0 | my $self = shift; | |||||||||||||||||||
| 420 | 0 | return $self->oim_get_field(@_); | |||||||||||||||||||
| 421 | } | ||||||||||||||||||||
| 422 | |||||||||||||||||||||
| 423 | 0 | ▶ | sub get_persistent_field { | ||||||||||||||||||
|
Subroutine
get_persistent_field: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 424 | 0 | my $self = shift; | |||||||||||||||||||
| 425 | 0 | return $self->oim_get_persistent_field(@_); | |||||||||||||||||||
| 426 | } | ||||||||||||||||||||
| 427 | |||||||||||||||||||||
| 428 | 0 | ▶ | sub sweep_to_field { | ||||||||||||||||||
|
Subroutine
sweep_to_field: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 429 | 0 | my ( $self, %args ) = validated_getter( | |||||||||||||||||||
| 430 | \@_, | ||||||||||||||||||||
| 431 | target => { isa => 'Num' }, | ||||||||||||||||||||
| 432 | rate => { isa => 'Num' }, | ||||||||||||||||||||
| 433 | ); | ||||||||||||||||||||
| 434 | |||||||||||||||||||||
| 435 | 0 | my $point = delete $args{target}; | |||||||||||||||||||
| 436 | 0 | my $rate = delete $args{rate}; | |||||||||||||||||||
| 437 | |||||||||||||||||||||
| 438 | 0 | $self->config_sweep( point => $point, rate => $rate, %args ); | |||||||||||||||||||
| 439 | |||||||||||||||||||||
| 440 | 0 | $self->trg(%args); | |||||||||||||||||||
| 441 | |||||||||||||||||||||
| 442 | 0 | $self->wait(%args); | |||||||||||||||||||
| 443 | |||||||||||||||||||||
| 444 | 0 | return $self->oim_get_field(%args); | |||||||||||||||||||
| 445 | } | ||||||||||||||||||||
| 446 | |||||||||||||||||||||
| 447 | 0 | ▶ | sub config_sweep { | ||||||||||||||||||
|
Subroutine
config_sweep: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 448 | 0 | my ( $self, %args ) = validated_hash( | |||||||||||||||||||
| 449 | \@_, | ||||||||||||||||||||
| 450 | point => { isa => 'Num' }, | ||||||||||||||||||||
| 451 | rate => { isa => 'Num' }, | ||||||||||||||||||||
| 452 | ); | ||||||||||||||||||||
| 453 | 0 | my $target = delete $args{point}; | |||||||||||||||||||
| 454 | 0 | my $rate = delete $args{rate}; | |||||||||||||||||||
| 455 | |||||||||||||||||||||
| 456 | 0 | my $setrate = $self->oim_set_field_sweeprate( value => $rate, %args ); | |||||||||||||||||||
| 457 | 0 | my $setpoint = $self->oim_set_field_setpoint( value => $target, %args ); | |||||||||||||||||||
| 458 | 0 | ▶ | if ( $self->verbose() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 459 | 0 | say "config_sweep: setpoint: $setpoint (T), rate: $setrate (T/min)"; | |||||||||||||||||||
| 460 | } | ||||||||||||||||||||
| 461 | } | ||||||||||||||||||||
| 462 | |||||||||||||||||||||
| 463 | # In go_to_next_step, the XPRESS will call the sequence | ||||||||||||||||||||
| 464 | # config_sweep(...); | ||||||||||||||||||||
| 465 | # trg(); | ||||||||||||||||||||
| 466 | # wait(); | ||||||||||||||||||||
| 467 | |||||||||||||||||||||
| 468 | 0 | ▶ | sub trg { | ||||||||||||||||||
|
Subroutine
trg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 469 | 0 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||||||||||||
| 470 | 0 | $self->oim_set_activity( value => 'RTOS', %args ); | |||||||||||||||||||
| 471 | } | ||||||||||||||||||||
| 472 | |||||||||||||||||||||
| 473 | 0 | ▶ | sub wait { | ||||||||||||||||||
|
Subroutine
wait: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 474 | 0 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||||||||||||
| 475 | 0 | my $target = $self->oim_get_field_setpoint(%args); | |||||||||||||||||||
| 476 | 0 | my $verbose = $self->verbose(); | |||||||||||||||||||
| 477 | |||||||||||||||||||||
| 478 | # enable autoflush | ||||||||||||||||||||
| 479 | 0 | my $autoflush = STDOUT->autoflush(); | |||||||||||||||||||
| 480 | 0 | my $last_field; | |||||||||||||||||||
| 481 | 0 | my $time_step = 1; | |||||||||||||||||||
| 482 | 0 | while (1) { | |||||||||||||||||||
| 483 | 0 | sleep $time_step; | |||||||||||||||||||
| 484 | 0 | my $field = $self->oim_get_field(%args); | |||||||||||||||||||
| 485 | |||||||||||||||||||||
| 486 | 0 | ▶ | if ($verbose) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 487 | 0 | my $rate; | |||||||||||||||||||
| 488 | 0 | ▶ | if ( defined $last_field ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 489 | 0 | $rate = ( $field - $last_field ) * 60 / $time_step; | |||||||||||||||||||
| 490 | 0 | $rate = sprintf( "%.5g", $rate ); | |||||||||||||||||||
| 491 | } | ||||||||||||||||||||
| 492 | else { | ||||||||||||||||||||
| 493 | 0 | $rate = "unknown"; | |||||||||||||||||||
| 494 | } | ||||||||||||||||||||
| 495 | 0 | printf( | |||||||||||||||||||
| 496 | "Field: %.6e T, Estimated rate: $rate T/min \r", | ||||||||||||||||||||
| 497 | $field | ||||||||||||||||||||
| 498 | ); | ||||||||||||||||||||
| 499 | 0 | $last_field = $field; | |||||||||||||||||||
| 500 | } | ||||||||||||||||||||
| 501 | |||||||||||||||||||||
| 502 | 0 | ▶ | if ( abs( $field - $target ) < $self->max_field_deviation() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 503 | 0 | last; | |||||||||||||||||||
| 504 | } | ||||||||||||||||||||
| 505 | } | ||||||||||||||||||||
| 506 | |||||||||||||||||||||
| 507 | 0 | ▶ | if ($verbose) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 508 | 0 | print " " x 70 . "\r"; | |||||||||||||||||||
| 509 | } | ||||||||||||||||||||
| 510 | |||||||||||||||||||||
| 511 | # reset autoflush to previous value | ||||||||||||||||||||
| 512 | 0 | STDOUT->autoflush($autoflush); | |||||||||||||||||||
| 513 | |||||||||||||||||||||
| 514 | } | ||||||||||||||||||||
| 515 | |||||||||||||||||||||
| 516 | 0 | ▶ | sub active { | ||||||||||||||||||
|
Subroutine
active: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 517 | 0 | my $self = shift; | |||||||||||||||||||
| 518 | |||||||||||||||||||||
| 519 | # with the legacy command set, one could use the "X" command to find | ||||||||||||||||||||
| 520 | # whether the magnet has finshed the sweep | ||||||||||||||||||||
| 521 | # We do it manually by comparing field and setpoint. | ||||||||||||||||||||
| 522 | 0 | my $field = $self->oim_get_field(); | |||||||||||||||||||
| 523 | 0 | my $target = $self->oim_get_field_setpoint(); | |||||||||||||||||||
| 524 | 0 | ▶ | if ( abs( $field - $target ) < $self->max_field_deviation() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 525 | 0 | return 0; | |||||||||||||||||||
| 526 | } | ||||||||||||||||||||
| 527 | else { | ||||||||||||||||||||
| 528 | 0 | return 1; | |||||||||||||||||||
| 529 | } | ||||||||||||||||||||
| 530 | } | ||||||||||||||||||||
| 531 | |||||||||||||||||||||
| 532 | 0 | ▶ | sub exit { | ||||||||||||||||||
|
Subroutine
exit: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 533 | 0 | my ( $self, %args ) = validated_getter( \@_ ); | |||||||||||||||||||
| 534 | 0 | $self->oim_set_activity( value => 'HOLD', %args ); | |||||||||||||||||||
| 535 | } | ||||||||||||||||||||
| 536 | |||||||||||||||||||||
| 537 | 2 | __PACKAGE__->meta()->make_immutable(); | |||||||||||||||||||
| 538 | |||||||||||||||||||||
| 539 | 2 | 1; | |||||||||||||||||||
| 540 | |||||||||||||||||||||
| 541 | __END__ | ||||||||||||||||||||