XPRESS/Sweep/Magnet.pm untested

filter: Statementstmt 0.0% 0 / 75 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 120 CC 12 SCAR 24.0
CC
12
Cov
0%
go_to_sweep_start
20.0
exit_loop
20.0
go_to_next_step
12.0
CRAP 11.0
1 package Lab::XPRESS::Sweep::Magnet;
2 $Lab::XPRESS::Sweep::Magnet::VERSION = '3.899';
3 #ABSTRACT: Magnetic field sweep
4  
5 use v5.20;
6  
7 use Lab::XPRESS::Sweep;
8 use Time::HiRes qw/usleep/, qw/time/;
9 use strict;
10  
11 our @ISA = ('Lab::XPRESS::Sweep');
12  
13 sub new {
14 my $proto = shift;
15 my @args = @_;
16 my $class = ref($proto) || $proto;
17 my $self->{default_config} = {
18 id => 'Magnet_sweep',
19 filename_extension => 'B=',
20 interval => 1,
21 points => [],
22 duration => [],
23 mode => 'continuous',
24 allowed_instruments => [
25 'Lab::Instrument::IPS',
26 'Lab::Instrument::IPSWeiss1',
27 'Lab::Instrument::IPSWeiss2',
28 'Lab::Instrument::IPSWeissDillFridge',
29 'Lab::Instrument::IPSStrunkDillFridge',
30 'Lab::Moose::Instrument::OI_Mercury::Magnet',
31 ],
32 allowed_sweep_modes => [ 'continuous', 'list', 'step' ],
33 use_persistentmode => 0,
34 number_of_points => [undef]
35 };
36  
37 $self = $class->SUPER::new( $self->{default_config}, @args );
38 bless( $self, $class );
39  
40 return $self;
41 }
42  
43 sub go_to_sweep_start {
44 my $self = shift;
45  
46 if ( $self->{config}->{use_persistentmode} ) {
47 if ( !$self->{config}->{instrument}->{device_settings}
48 ->{has_switchheater} ) {
49 warn
50 "Persistent sweep mode requires a switchheater. Persistent sweep mode is switched off.\n";
51 $self->{config}->{use_persistentmode} = 0;
52 }
53 else {
54 $self->{config}->{instrument}->set_persistent_mode(0);
55 }
56  
57 }
58  
59 # go to start:
60 print "going to start ... ";
61 $self->{config}->{instrument}->sweep_to_field(
62 {
63 'target' => @{ $self->{config}->{points} }[0],
64 'rate' => @{ $self->{config}->{rate} }[0]
65 }
66 );
67  
68 $self->{config}->{instrument}->set_persistent_mode(1)
69 if $self->{config}->{use_persistentmode};
70  
71 print "done\n";
72  
73 }
74  
75 sub start_continuous_sweep {
76 my $self = shift;
77  
78 if ( $self->{config}->{use_persistentmode} ) {
79 $self->{config}->{instrument}->set_persistent_mode(0);
80 }
81  
82 # continuous sweep:
83 $self->{config}->{instrument}->config_sweep(
84 {
85 'points' => $self->{config}->{points},
86 'rates' => $self->{config}->{rate}
87 }
88 );
89 $self->{config}->{instrument}->trg();
90  
91 }
92  
93 sub go_to_next_step {
94 my $self = shift;
95  
96 $self->{config}->{instrument}->set_persistent_mode(0)
97 if $self->{config}->{use_persistentmode};
98  
99 # step mode:
100 $self->{config}->{instrument}->config_sweep(
101 {
102 'points' => @{ $self->{config}->{points} }[ $self->{iterator} ],
103 'rates' => @{ $self->{config}->{rate} }[ $self->{iterator} ]
104 }
105 );
106  
107 $self->{config}->{instrument}->trg();
108 $self->{config}->{instrument}->wait();
109  
110 $self->{config}->{instrument}->set_persistent_mode(1)
111 if $self->{config}->{use_persistentmode};
112  
113 }
114  
115 sub exit_loop {
116 my $self = shift;
117 if ( not $self->{config}->{instrument}->active() ) {
118 if ( $self->{config}->{mode} =~ /step|list/ ) {
119 if (
120 not defined @{ $self->{config}->{points} }
121 [ $self->{iterator} + 1 ] ) {
122 return 1;
123 }
124 else {
125 return 0;
126 }
127 }
128 return 1;
129 }
130 else {
131 return 0;
132 }
133 }
134  
135 sub get_value {
136 my $self = shift;
137 if ( $self->{config}->{use_persistentmode} ) {
138 return $self->{config}->{instrument}->get_persistent_field();
139 }
140 else {
141 return $self->{config}->{instrument}->get_field();
142 }
143 }
144  
145 sub exit {
146 my $self = shift;
147 $self->{config}->{instrument}->set_persistent_mode(1)
148 if $self->{config}->{use_persistentmode};
149 $self->{config}->{instrument}->abort();
150  
151 }
152  
153 1;
154  
155 __END__