Moose/Instrument/AMI_430.pm

filter: Statementstmt 28.8% 34 / 118 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 9 / 27 Podpod 18.7% 3 / 16 totaltotal 24.7% 46 / 186 SCAR 43.2
CC
12
Cov
24%
_check_sweep_parameters
20.0
active
12.0
set_field_ramp_rate
6.0
CRAP 74.9
« Moose/Connection/VXI11.pm ↑ Summary Instrument/OI_Triton.pm »
1 package Lab::Moose::Instrument::AMI_430;
2 #ABSTRACT: American Magnetics magnet power supply
3 1 $Lab::Moose::Instrument::AMI_430::VERSION = '3.881';
4 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moose::Util::TypeConstraints qw/enum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 use Lab::Moose::Instrument
10 1 ▶ qw/validated_getter validated_setter setter_params validated_no_param_setter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Lab::Moose::Instrument::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Time::HiRes qw (usleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 extends 'Lab::Moose::Instrument';
17  
18  
19 1 has max_field => (
20 is => 'ro',
21 isa => 'Lab::Moose::PosNum',
22 required => 1,
23 );
24  
25 1 has max_rate => (
26 is => 'ro',
27 isa => 'Lab::Moose::PosNum',
28 required => 1,
29 );
30  
31 1 has verbose => (
32 is => 'ro',
33 isa => 'Bool',
34 default => 1
35 );
36  
37  
38 sub BUILD {
39 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
40  
41 0 $self->clear();
42 0 $self->cls();
43 }
44  
45 around default_connection_options => sub {
46 0 ▶ my $orig = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 my $self = shift;
48 0 my $options = $self->$orig();
49 0 $options->{Socket}{port} = 7180;
50 0 $options->{Socket}{timeout} = 10;
51 0 $options->{Socket}{write_termchar} = "\r\n";
52
53 0 return $options;
54 1 };
55  
56 sub cls {
57 0 ▶ my ( $self, %args ) = validated_getter( \@_ );
Subroutine cls: not called CC=1 SCAR=6.9
Pod undocumented
58 0 return $self->query( command => "*CLS", %args );
59 }
60  
61 sub idn {
62 0 ▶ my ( $self, %args ) = validated_getter( \@_ );
Subroutine idn: not called CC=1 SCAR=6.9
Pod documented
63 0 return $self->query( command => "*IDN?", %args );
64 }
65  
66 sub get_field_ramp_rate {
67 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine get_field_ramp_rate: not called CC=1 SCAR=6.9
Pod undocumented
68 \@_
69 );
70 0 return $self->query( command => "RAMP:RATE:FIELD:1?", %args );
71 }
72  
73 sub set_field_ramp_rate {
74 0 ▶ my ( $self, $value, %args ) = validated_setter(
Subroutine set_field_ramp_rate: not called CC=2 SCAR=17.9
Pod undocumented
75 \@_,
76 value => { isa => 'Lab::Moose::PosNum' }
77 );
78 0 my $max_rate = $self->max_rate();
79 0 ▶ if( $value > $max_rate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > $max_rate) 0 0 0
80 0 croak("Ramp rate $value T/min higher than max rate $max_rate T/min!");
81 }
82 0 my $max_field = $self->max_field();
83 0 return $self->write( command => "CONFIGURE:RAMP:RATE:FIELD 1,$value,$max_field", %args );
84 }
85  
86 sub get_field {
87 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine get_field: not called CC=1 SCAR=6.9
Pod undocumented
88 \@_
89 );
90 0 return $self->query( command => "FIELD:MAGNET?", %args );
91 }
92  
93 sub get_value {
94 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine get_value: not called CC=1 SCAR=6.9
Pod undocumented
95 \@_
96 );
97 0 return $self->get_field(@_);
98 }
99  
100 sub get_target_field {
101 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine get_target_field: not called CC=1 SCAR=6.9
Pod undocumented
102 \@_
103 );
104 0 return $self->query( command => "FIELD:TARGET?", %args );
105 }
106  
107 sub set_target_field {
108 0 ▶ my ( $self, $value, %args ) = validated_setter(
Subroutine set_target_field: not called CC=2 SCAR=17.9
Pod undocumented
109 \@_,
110 value => { isa => 'Num' }
111 );
112 0 my $max_field = $self->max_field();
113 0 ▶ if( $value > $max_field ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > $max_field) 0 0 0
114 0 croak("Requested field $value T higher than allowed maximum field strength $max_field T!");
115 }
116 0 return $self->write( command => "CONFIGURE:FIELD:TARGET $value", %args );
117 }
118  
119 sub sweep_to_field {
120 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine sweep_to_field: not called CC=1 SCAR=6.9
Pod documented
121 \@_,
122 target => { isa => 'Num' },
123 rate => { isa => 'Num' },
124 );
125  
126 0 my $point = delete $args{target};
127 0 my $rate = delete $args{rate};
128  
129 0 $self->config_sweep( point => $point, rate => $rate, %args );
130  
131 0 $self->trg(%args);
132  
133 0 $self->wait(%args);
134 0 return $self->get_field(%args);
135 }
136  
137 sub ramp {
138 0 ▶ my ( $self, %args ) = validated_getter( \@_ );
Subroutine ramp: not called CC=2 SCAR=17.9
Pod undocumented
139
140 0 my $ret_val = $self->write( command => "RAMP", %args );
141 0 ▶ while ($self->active()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->active) 0 0 0
142 0 sleep(2);
143 }
144 0 return $ret_val;
145 }
146  
147 sub to_zero {
148 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine to_zero: not called CC=2 SCAR=17.9
Pod documented
149 \@_
150 );
151 0 my $ret_val = $self->write( command => "ZERO", %args );
152 0 ▶ while ($self->active()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->active) 0 0 0
153 0 sleep(2);
154 }
155 0 return $ret_val;
156 }
157  
158 # Methods for sweep
159  
160 sub config_sweep {
161 0 ▶ my ( $self, %args ) = validated_hash(
Subroutine config_sweep: not called CC=2 SCAR=17.9
Pod undocumented
162 \@_,
163 point => { isa => 'Num' },
164 rate => { isa => 'Num' },
165 );
166 0 my $target = delete $args{point};
167 0 my $rate = delete $args{rate};
168  
169 0 $self->set_target_field( value => $target, %args );
170 0 $self->set_field_ramp_rate( value => $rate, %args );
171  
172 0 my $current_field = $self->get_field();
173 0 $self->_check_sweep_parameters(
174 current => $current_field, target => $target,
175 rate => $rate
176 );
177 0 ▶ if ( $self->verbose() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
178 0 say "config_sweep: target: $target (T), rate: $rate (T/min)";
179 }
180 }
181  
182 sub trg {
183 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine trg: not called CC=1 SCAR=6.9
Pod undocumented
184 \@_
185 );
186 0 return $self->write( command => "RAMP", %args );
187 }
188  
189 sub active {
190 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine active: not called CC=3 SCAR=24.8
Pod undocumented
191 \@_,
192 );
193 0 my $status = $self->query( command => "STATE?", %args );
194 # Holding at the target field OR At zero current
195 0 ▶ if($status eq 2 || $status eq 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status eq 2 or $status eq 8) { } 0 0 0
Condition0%0/3
$status eq 2 or $status eq 8
l!l&&r!l&&!r
000
MC/DC0%0/2
$status eq 2 or $status eq 8
$status eq 2 $status eq 8
Truth table0%0/3
A or B
A= $status eq 2B= $status eq 8
ABresult
1X1
011
000
196 0 return 0
197 } else {
198 0 return 1
199 }
200 }
201  
202 sub wait {
203 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine wait: not called CC=2 SCAR=17.9
Pod undocumented
204 \@_,
205 );
206  
207 0 my $autoflush = STDOUT->autoflush();
208  
209 0 ▶ while ($self->active()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->active) 0 0 0
210 0 sleep(1);
211 0 printf( "Field: %.3fT\r", $self->get_field(%args) );
212 }
213
214 0 STDOUT->autoflush($autoflush);
215 }
216  
217 sub _check_sweep_parameters {
218 0 ▶ my ( $self, %args ) = validated_hash(
Subroutine _check_sweep_parameters: not called CC=4 SCAR=30.0
219 \@_,
220 current => { isa => 'Num' },
221 target => { isa => 'Num' },
222 rate => { isa => 'Num' },
223 );
224  
225 0 my $current = abs( delete $args{current} );
226 0 my $target = abs( delete $args{target} );
227 0 my $rate = abs( delete $args{rate} );
228  
229 0 ▶ my $max_field = ( $current > $target ) ? $current : $target;
Branch: 1 branch
BranchTrueFalseTotal
$current > $target ? : 0 0 0
230  
231 0 my $maximum_allowed_field = $self->max_field();
232  
233 0 my $i = 0;
234  
235 0 ▶ if ( $max_field > $maximum_allowed_field ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_field > $maximum_allowed_field) 0 0 0
236 0 croak
237 "target field $max_field exceeds absolute maximum field $maximum_allowed_field";
238 }
239  
240  
241 0 my $max_rate = $self->max_rate();
242 0 ▶ if ( $rate > $max_rate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rate > $max_rate) 0 0 0
243 0 croak "Rate $rate exceeds maximum allowed rate $max_rate";
244 }
245 }
246  
247 1 __PACKAGE__->meta()->make_immutable();
248  
249 1 1;
250  
251 __END__
252  
253 =pod
254  
255 =encoding UTF-8
256  
257 =head1 NAME
258  
259 Lab::Moose::Instrument::AMI_430 - American Magnetics magnet power supply
260  
261 =head1 VERSION
262  
263 version 3.881
264  
265 =head1 SYNOPSIS
266  
267 use Lab::Moose;
268  
269 # Constructor
270 my $magnet_z = instrument(
271 type => 'AMI_430',
272 connection_type => 'Socket',
273 connection_options => { host => '169.254.226.70' },
274 max_field => 1.0,
275 max_rate => 0.1,
276 );
277  
278 $magnet_sweep = sweep(
279 type => 'Continuous::Magnet',
280 instrument => $magnet_z,
281 from => -0.2, to => 0.2, interval => 1,
282 )
283  
284 Setting the maximum allowed field strength and the maximum rate are mandatory.
285 This model allows to change the units for field strength (kG/T) and time (min/s).
286 You can check this in the menu on the front panel.
287 For security purposes this driver does not allow changing those critical settings.
288  
289 =head1 METHODS
290  
291 =head2 idn
292  
293 say $magnet_z->idn();
294  
295 Returns the identification string of the device. It contains the AMI model
296 number and firmware revision code.
297  
298 =head2 sweep_to_field
299  
300 $magnet_z->sweep_to_field( target => 0.5, rate => 0.02 );
301  
302 Checks the provided field strength and rate and starts a sweep.
303 This function waits for the device to finish.
304  
305 =head2 to_zero
306  
307 $magnet_z->to_zero()
308  
309 Sweeps back to zero with the maximum allowed rate.
310 This function waits for the device to finish.
311  
312 =head1 COPYRIGHT AND LICENSE
313  
314 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
315  
316 Copyright 2023 Mia Schambeck
317  
318  
319 This is free software; you can redistribute it and/or modify it under
320 the same terms as the Perl 5 programming language system itself.
321  
322 =cut
« Moose/Connection/VXI11.pm ↑ Summary Instrument/OI_Triton.pm »