XPRESS/Sweep/Level.pm untested

filter: Statementstmt 0.0% 0 / 104 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 150 CC 9 SCAR 27.2
CC
9
Cov
0%
exit_loop
42.0
go_to_sweep_start
12.0
go_to_next_step
6.0
CRAP 15.2
1 package Lab::XPRESS::Sweep::Level;
2 $Lab::XPRESS::Sweep::Level::VERSION = '3.899';
3 #ABSTRACT: Level (e.g. Voltage or Current) sweep
4  
5 use v5.20;
6  
7 use Lab::XPRESS::Sweep;
8 use Time::HiRes qw/usleep/, qw/time/;
9 use warnings;
10 use strict;
11 use Carp;
12 our @ISA = ('Lab::XPRESS::Sweep');
13  
14 sub new {
15 my $proto = shift;
16 my @args = @_;
17 my $class = ref($proto) || $proto;
18 my $self->{default_config} = {
19 id => 'Level_sweep',
20 filename_extension => 'Level=',
21 interval => 1,
22 points => [],
23 duration => [],
24 mode => 'continuous',
25 jump => 0,
26 allowed_instruments => [
27 qw/
28 Lab::Instrument::Yokogawa7651 Lab::Instrument::Keithley2400
29 Lab::Instrument::YokogawaGS200 Lab::Instrument::DummySource
30 Lab::Instrument::SR830::AuxOut Lab::Moose::Instrument::DummySource
31 Lab::Moose::Instrument::YokogawaGS200 Lab::Moose::Instrument::ZI_MFLI Lab::Moose::Instrument::ZI_MFIA/
32 ],
33 allowed_sweep_modes => [ 'continuous', 'list', 'step' ],
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 # go to start:
47 print "Setting level to start value ... ";
48 if ( $self->{config}->{mode} =~ /step|list/
49 && $self->{config}->{jump} ) {
50 my $target = $self->{config}{points}[ $self->{iterator} ];
51 my $rate = $self->{config}{rate}[ $self->{iterator} ];
52 my $current = $self->{config}{instrument}->get_level();
53 my $stepwidth = $self->{config}{stepwidth}[ $self->{iterator} ];
54 if ( not defined $stepwidth ) {
55 croak "no 'stepwidth' defined for sweep with mode 'step'";
56 }
57 my $time = abs( ( $target - $current ) / $rate );
58 $self->{config}{instrument}
59 ->sweep_to_level( $target, $time, $stepwidth );
60 }
61 else {
62 $self->{config}->{instrument}->config_sweep(
63 {
64 'points' =>
65 @{ $self->{config}->{points} }[ $self->{iterator} ],
66 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} ]
67 }
68 );
69 $self->{config}->{instrument}->trg();
70 $self->{config}->{instrument}->wait();
71 }
72 print "Done \n";
73  
74 }
75  
76 sub start_continuous_sweep {
77 my $self = shift;
78  
79 $self->{config}->{instrument}->config_sweep(
80 {
81 'points' =>
82 @{ $self->{config}->{points} }[ $self->{iterator} + 1 ],
83 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} + 1 ]
84 }
85 );
86 $self->{config}->{instrument}->trg();
87 }
88  
89 sub go_to_next_step {
90 my $self = shift;
91  
92 if ( $self->{config}->{jump} == 1 ) {
93 $self->{config}->{instrument}->set_level(
94 ${ $self->{config}->{points} }[ $self->{iterator} ] );
95 }
96 else {
97 $self->{config}->{instrument}->config_sweep(
98 {
99 'points' =>
100 @{ $self->{config}->{points} }[ $self->{iterator} ],
101 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} ]
102 }
103 );
104 $self->{config}->{instrument}->trg();
105 $self->{config}->{instrument}->wait();
106 }
107 }
108  
109 sub exit_loop {
110 my $self = shift;
111  
112 # if ( not $self->{config}->{instrument}->active() ) {
113 if ( $self->{config}->{mode} =~ /step|list/ ) {
114 if (
115 not
116 defined @{ $self->{config}->{points} }[ $self->{iterator} + 1 ] )
117 {
118 return 1;
119 }
120 return 0;
121 }
122 if ( not $self->{config}->{instrument}->active() ) {
123 if ( $self->{config}->{mode} eq "continuous" ) {
124 if (
125 not defined @{ $self->{config}->{points} }
126 [ $self->{sequence} + 2 ] ) {
127 return 1;
128 }
129 $self->{sequence}++;
130 $self->{config}->{instrument}->config_sweep(
131 {
132 'points' => @{ $self->{config}->{points} }
133 [ $self->{sequence} + 1 ],
134 'rate' =>
135 @{ $self->{config}->{rate} }[ $self->{sequence} + 1 ]
136 }
137 );
138 $self->{config}->{instrument}->trg();
139 }
140 return 0;
141 }
142 else {
143 return 0;
144 }
145 }
146  
147 sub get_value {
148 my $self = shift;
149 return $self->{config}->{instrument}->get_level();
150 }
151  
152 sub exit {
153 my $self = shift;
154 $self->{config}->{instrument}->abort();
155 }
156  
157 1;
158  
159 __END__