File Coverage

blib/lib/Lab/Instrument/DummySource.pm
Criterion Covered Total %
statement 35 55 63.6
branch 2 2 100.0
condition 1 9 11.1
subroutine 10 16 62.5
pod 4 9 44.4
total 52 91 57.1


line stmt bran cond sub pod time code
1             package Lab::Instrument::DummySource;
2             #ABSTRACT: Dummy voltage source
3             $Lab::Instrument::DummySource::VERSION = '3.880';
4 3     3   3062 use v5.20;
  3         17  
5              
6 3     3   29 use warnings;
  3         10  
  3         77  
7 3     3   20 use strict;
  3         5  
  3         60  
8              
9 3     3   17 use Data::Dumper;
  3         6  
  3         189  
10              
11 3     3   27 use parent 'Lab::Instrument::Source';
  3         7  
  3         33  
12              
13             our %fields = (
14             supported_connections => ['DEBUG'],
15              
16             connection_settings => {},
17              
18             device_settings => {
19              
20             # gate_protect => 1,
21             # gp_equal_level => 1e-5,
22             # gp_max_units_per_second => 0.002,
23             # gp_max_units_per_step => 0.001,
24             # gp_max_step_per_second => 2,
25              
26             max_sweep_time => 3600,
27             min_sweep_time => 0.1,
28             },
29              
30             device_cache => {
31             function => "Voltage",
32             range => 10,
33             level => 0,
34             output => undef,
35             },
36              
37             device_cache_order => [ 'function', 'range' ],
38             );
39              
40             sub new {
41 2     2 1 6 my $proto = shift;
42 2   33     50 my $class = ref($proto) || $proto;
43 2         17 my $self = $class->SUPER::new(@_);
44 2         13 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
  2         27  
45              
46 2         146 print "DS: Created dummy instrument with config\n";
47 2         8 while ( my ( $k, $v ) = each %{ $self->device_settings() } ) {
  36         199  
48 34 100       74 $v = 'undef' if !defined($v);
49 34         1923 print "DS: $k -> $v\n";
50             }
51              
52 2         14 return $self;
53             }
54              
55             sub _device_init {
56 2     2   3 my $self = shift;
57 2         5 return;
58             }
59              
60             # sub config_sweep {
61             # my $self = shift;
62             # my ($start, $target, $duration,$sections ,$tail) = $self->check_sweep_config(@_);
63              
64             # print "Dummy Source sweep configuration.\n";
65             # print "Duration: $duration\n";
66             # $self->{'sweeptime'} = $duration;
67             # }
68              
69             sub trg {
70 0     0 0 0 print "Dummy Source received trigger.\n";
71             }
72              
73             sub wait {
74 0     0 0 0 my $self = shift;
75 0         0 print "Dummy Source is sweeping.\n";
76 0         0 sleep( $self->{'sweeptime'} );
77             }
78              
79             sub _set_level {
80 11     11   20 my $self = shift;
81 11         35 my ( $value, $tail ) = $self->_check_args( \@_, ['value'] );
82 11         1368 say "DS: setting level to $value";
83 11         106 return $self->{'device_cache'}->{'level'} = $value;
84             }
85              
86             sub set_voltage {
87 11     11 0 17 my $self = shift;
88 11         44 my ( $voltage, $tail ) = $self->_check_args( \@_, ['voltage'] );
89 11         42 return $self->set_level( $voltage, $tail );
90             }
91              
92             sub get_level {
93 0     0 1 0 my $self = shift;
94              
95 0         0 return $self->{'device_cache'}->{'level'};
96             }
97              
98             sub active {
99 0     0 0 0 return 0;
100             }
101              
102             sub abort {
103 2     2 0 4 return 0;
104             }
105              
106             sub set_range {
107 0     0 1   my $self = shift;
108 0           my $range = shift;
109 0           my $args = {@_};
110 0   0       my $channel = $args->{'channel'} || $self->default_channel();
111              
112 0           my $tmp = "last_range_$channel";
113 0           $self->{$tmp} = $range;
114 0           print "DS: setting virtual range of channel $channel to $range\n";
115             }
116              
117             sub get_range {
118 0     0 1   my $self = shift;
119 0           my $args = {@_};
120 0   0       my $channel = $args->{'channel'} || $self->default_channel();
121              
122 0           my $tmp = "last_range_$channel";
123 0           print "DS: getting virtual range: $$self{$tmp}\n";
124 0           return $self->{$tmp};
125             }
126              
127             1;
128              
129             __END__
130              
131             =pod
132              
133             =encoding utf-8
134              
135             =head1 NAME
136              
137             Lab::Instrument::DummySource - Dummy voltage source
138              
139             =head1 VERSION
140              
141             version 3.880
142              
143             =head1 DESCRIPTION
144              
145             The Lab::Instrument::DummySource class implements a dummy voltage source
146             that does nothing but can be used for testing purposes.
147              
148             Only developers will ever make use of this class.
149              
150             =head1 SEE ALSO
151              
152             =over 4
153              
154             =item (L<Lab::Instrument::Source>).
155              
156             =back
157              
158             =head1 COPYRIGHT AND LICENSE
159              
160             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
161              
162             Copyright 2011 Andreas K. Huettel, Florian Olbrich
163             2012 Alois Dirnaichner
164             2015 Alois Dirnaichner
165             2016 Simon Reinhardt
166             2017 Andreas K. Huettel
167             2020 Andreas K. Huettel
168              
169              
170             This is free software; you can redistribute it and/or modify it under
171             the same terms as the Perl 5 programming language system itself.
172              
173             =cut