line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lab::Moose::Instrument::DummySource; |
2
|
|
|
|
|
|
|
$Lab::Moose::Instrument::DummySource::VERSION = '3.881'; |
3
|
|
|
|
|
|
|
#ABSTRACT: Dummy YokogawaGS200 source for use with 'Debug' connection |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
4215
|
use v5.20; |
|
4
|
|
|
|
|
15
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
25
|
use Moose; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
34
|
|
9
|
4
|
|
|
4
|
|
32529
|
use MooseX::Params::Validate; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
37
|
|
10
|
|
|
|
|
|
|
use Lab::Moose::Instrument |
11
|
4
|
|
|
4
|
|
2041
|
qw/validated_getter validated_setter setter_params/; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
280
|
|
12
|
4
|
|
|
4
|
|
30
|
use Carp; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
248
|
|
13
|
4
|
|
|
4
|
|
1926
|
use Lab::Moose::Instrument::Cache; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
30
|
|
14
|
4
|
|
|
4
|
|
2519
|
use Time::HiRes qw/time sleep/; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
51
|
|
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
684
|
use namespace::autoclean; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
28
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
extends 'Lab::Moose::Instrument'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has [ |
21
|
|
|
|
|
|
|
qw/ |
22
|
|
|
|
|
|
|
max_units_per_second |
23
|
|
|
|
|
|
|
max_units_per_step |
24
|
|
|
|
|
|
|
min_units |
25
|
|
|
|
|
|
|
max_units |
26
|
|
|
|
|
|
|
/ |
27
|
|
|
|
|
|
|
] => ( is => 'ro', isa => 'Num', required => 1 ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has source_level_timestamp => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
isa => 'Num', |
32
|
|
|
|
|
|
|
init_arg => undef, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has verbose => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
isa => 'Bool', |
38
|
|
|
|
|
|
|
default => 1 |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# |
42
|
|
|
|
|
|
|
# Internal variables for continous sweep |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has _sweep_start_time => ( |
46
|
|
|
|
|
|
|
is => 'rw', |
47
|
|
|
|
|
|
|
isa => 'Lab::Moose::PosNum', |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has _active => ( |
51
|
|
|
|
|
|
|
is => 'rw', |
52
|
|
|
|
|
|
|
isa => 'Bool', |
53
|
|
|
|
|
|
|
default => 0 |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has _sweep_target_level => ( |
57
|
|
|
|
|
|
|
is => 'rw', |
58
|
|
|
|
|
|
|
isa => 'Num', |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has _sweep_start_level => ( |
62
|
|
|
|
|
|
|
is => 'rw', |
63
|
|
|
|
|
|
|
isa => 'Num', |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has _sweep_rate => ( |
67
|
|
|
|
|
|
|
is => 'rw', |
68
|
|
|
|
|
|
|
isa => 'Num', |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
with qw( |
72
|
|
|
|
|
|
|
Lab::Moose::Instrument::Common |
73
|
|
|
|
|
|
|
Lab::Moose::Instrument::LinearStepSweep |
74
|
|
|
|
|
|
|
Lab::Moose::Instrument::SCPI::Source::Function |
75
|
|
|
|
|
|
|
Lab::Moose::Instrument::SCPI::Source::Level |
76
|
|
|
|
|
|
|
Lab::Moose::Instrument::SCPI::Source::Range |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub BUILD { |
80
|
18
|
|
|
18
|
0
|
42
|
my $self = shift; |
81
|
18
|
|
|
|
|
96
|
$self->clear(); |
82
|
18
|
|
|
|
|
134
|
$self->cached_source_level(0); |
83
|
18
|
|
|
|
|
90
|
$self->cached_source_function('VOLT'); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# $self->cls(); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# FIXME: check protect params |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub set_level { |
92
|
167
|
|
|
167
|
0
|
773
|
my ( $self, $value, %args ) = validated_setter( |
93
|
|
|
|
|
|
|
\@_, |
94
|
|
|
|
|
|
|
value => { isa => 'Num' }, |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
167
|
|
|
|
|
5912
|
return $self->linear_step_sweep( |
98
|
|
|
|
|
|
|
to => $value, verbose => $self->verbose, |
99
|
|
|
|
|
|
|
%args |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub cached_level { |
104
|
5
|
|
|
5
|
0
|
11
|
my $self = shift; |
105
|
5
|
|
|
|
|
22
|
return $self->get_level(@_); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# return negative if sweep is done |
109
|
|
|
|
|
|
|
sub _remaining_sweep_time { |
110
|
25
|
|
|
25
|
|
89
|
my $self = shift; |
111
|
25
|
50
|
|
|
|
970
|
if ( not $self->_active ) { |
112
|
0
|
|
|
|
|
0
|
croak "no sweep"; |
113
|
|
|
|
|
|
|
} |
114
|
25
|
|
|
|
|
1148
|
my $start_time = $self->_sweep_start_time(); |
115
|
25
|
|
|
|
|
1038
|
my $rate = $self->_sweep_rate; |
116
|
25
|
|
|
|
|
1046
|
my $target_level = $self->_sweep_target_level; |
117
|
25
|
|
|
|
|
1020
|
my $start_level = $self->_sweep_start_level; |
118
|
|
|
|
|
|
|
|
119
|
25
|
100
|
|
|
|
138
|
my $sgn = $target_level >= $start_level ? 1 : -1; |
120
|
25
|
|
|
|
|
133
|
my $duration = abs( ( $target_level - $start_level ) / $rate ); |
121
|
25
|
|
|
|
|
195
|
return $duration - ( time() - $start_time ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub get_level { |
125
|
221
|
|
|
221
|
0
|
3002746
|
my ( $self, %args ) = validated_getter( \@_ ); |
126
|
|
|
|
|
|
|
|
127
|
221
|
100
|
|
|
|
123567
|
if ( $self->_active() ) { |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# in sweep |
130
|
|
|
|
|
|
|
|
131
|
14
|
|
|
|
|
86
|
my $remaining_time = $self->_remaining_sweep_time(); |
132
|
|
|
|
|
|
|
|
133
|
14
|
|
|
|
|
629
|
my $start_time = $self->_sweep_start_time(); |
134
|
14
|
|
|
|
|
617
|
my $rate = $self->_sweep_rate; |
135
|
14
|
|
|
|
|
607
|
my $target_level = $self->_sweep_target_level; |
136
|
14
|
|
|
|
|
596
|
my $start_level = $self->_sweep_start_level; |
137
|
|
|
|
|
|
|
|
138
|
14
|
100
|
|
|
|
87
|
my $sgn = $target_level >= $start_level ? 1 : -1; |
139
|
14
|
|
|
|
|
59
|
my $duration = abs( ( $target_level - $start_level ) / $rate ); |
140
|
14
|
100
|
|
|
|
65
|
if ( $remaining_time < 0 ) { |
141
|
3
|
|
|
|
|
126
|
$self->_active(0); |
142
|
3
|
|
|
|
|
28
|
$self->source_level( value => $target_level ); |
143
|
3
|
|
|
|
|
227
|
return $target_level; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
else { |
146
|
11
|
|
|
|
|
135
|
return $start_level + $sgn * $rate * ( time - $start_time ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
else { |
150
|
207
|
|
|
|
|
710
|
return $self->cached_source_level(); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub config_sweep { |
155
|
5
|
|
|
5
|
0
|
14
|
my $self = shift; |
156
|
5
|
|
|
|
|
25
|
my %args = @_; |
157
|
5
|
50
|
|
|
|
208
|
if ( $self->_active ) { |
158
|
0
|
|
|
|
|
0
|
croak("config_sweep called while instrument is active"); |
159
|
|
|
|
|
|
|
} |
160
|
5
|
|
|
|
|
15
|
my $target = $args{point}; |
161
|
5
|
|
|
|
|
16
|
my $rate = abs( $args{rate} ); |
162
|
5
|
|
|
|
|
21
|
$self->_sweep_start_level( $self->cached_level ); |
163
|
5
|
|
|
|
|
180
|
$self->_sweep_target_level($target); |
164
|
5
|
|
|
|
|
171
|
$self->_sweep_rate($rate); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub trg { |
168
|
5
|
|
|
5
|
0
|
11
|
my $self = shift; |
169
|
5
|
|
|
|
|
171
|
$self->_active(1); |
170
|
5
|
|
|
|
|
226
|
$self->_sweep_start_time( time() ); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub wait { |
174
|
2
|
|
|
2
|
0
|
1428
|
my $self = shift; |
175
|
2
|
|
|
|
|
118
|
my $start_time = $self->_sweep_start_time(); |
176
|
2
|
|
|
|
|
328
|
my $rate = $self->_sweep_rate; |
177
|
2
|
|
|
|
|
118
|
my $target_level = $self->_sweep_target_level; |
178
|
2
|
|
|
|
|
99
|
my $start_level = $self->_sweep_start_level; |
179
|
2
|
|
|
|
|
13
|
my $duration = abs( ( $target_level - $start_level ) / $rate ); |
180
|
|
|
|
|
|
|
|
181
|
2
|
100
|
|
|
|
23
|
if ( $start_time + $duration > time() ) { |
182
|
1
|
|
|
|
|
995374
|
sleep( $start_time + $duration - time() ); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Sweep done |
186
|
2
|
|
|
|
|
246
|
$self->_active(0); |
187
|
2
|
|
|
|
|
23
|
$self->source_level( value => $target_level ); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub active { |
191
|
14
|
|
|
14
|
0
|
2001049
|
my $self = shift; |
192
|
14
|
100
|
|
|
|
638
|
if ( not $self->_active ) { |
193
|
3
|
|
|
|
|
23
|
return 0; |
194
|
|
|
|
|
|
|
} |
195
|
11
|
100
|
|
|
|
83
|
if ( $self->_remaining_sweep_time > 0 ) { |
196
|
10
|
|
|
|
|
73
|
return 1; |
197
|
|
|
|
|
|
|
} |
198
|
1
|
|
|
|
|
18
|
return 0; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
__END__ |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=pod |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=encoding UTF-8 |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 NAME |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Lab::Moose::Instrument::DummySource - Dummy YokogawaGS200 source for use with 'Debug' connection |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 VERSION |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
version 3.881 |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 SYNOPSIS |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
use Lab::Moose; |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
my $source = instrument( |
224
|
|
|
|
|
|
|
type => 'DummySource', |
225
|
|
|
|
|
|
|
connection_type => 'Debug', |
226
|
|
|
|
|
|
|
connection_options => {verbose => 0}, |
227
|
|
|
|
|
|
|
# mandatory protection settings |
228
|
|
|
|
|
|
|
max_units_per_step => 0.001, # max step is 1mV/1mA |
229
|
|
|
|
|
|
|
max_units_per_second => 0.01, |
230
|
|
|
|
|
|
|
min_units => -10, |
231
|
|
|
|
|
|
|
max_units => 10, |
232
|
|
|
|
|
|
|
); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# Step-sweep to new level. |
235
|
|
|
|
|
|
|
# Stepsize and speed is given by (max|min)_units* settings. |
236
|
|
|
|
|
|
|
$source->set_level(value => 9); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# Get current level from device cache (without sending a query to the |
239
|
|
|
|
|
|
|
# instrument): |
240
|
|
|
|
|
|
|
my $level = $source->cached_level(); |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Copyright 2017 Simon Reinhardt |
247
|
|
|
|
|
|
|
2020 Andreas K. Huettel, Simon Reinhardt |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
251
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |