Instrument/DummySource.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 110 CC 2 SCAR 9.0
CC
2
Cov
0%
new
6.0
_device_init
2.0
trg
2.0
CRAP 2.5
1 package Lab::Instrument::DummySource;
2 #ABSTRACT: Dummy voltage source
3 $Lab::Instrument::DummySource::VERSION = '3.899';
4 use v5.20;
5  
6 use warnings;
7 use strict;
8  
9 use Data::Dumper;
10  
11 use parent 'Lab::Instrument::Source';
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 my $proto = shift;
42 my $class = ref($proto) || $proto;
43 my $self = $class->SUPER::new(@_);
44 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
45  
46 print "DS: Created dummy instrument with config\n";
47 while ( my ( $k, $v ) = each %{ $self->device_settings() } ) {
48 $v = 'undef' if !defined($v);
49 print "DS: $k -> $v\n";
50 }
51  
52 return $self;
53 }
54  
55 sub _device_init {
56 my $self = shift;
57 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 print "Dummy Source received trigger.\n";
71 }
72  
73 sub wait {
74 my $self = shift;
75 print "Dummy Source is sweeping.\n";
76 sleep( $self->{'sweeptime'} );
77 }
78  
79 sub _set_level {
80 my $self = shift;
81 my ( $value, $tail ) = $self->_check_args( \@_, ['value'] );
82 say "DS: setting level to $value";
83 return $self->{'device_cache'}->{'level'} = $value;
84 }
85  
86 sub set_voltage {
87 my $self = shift;
88 my ( $voltage, $tail ) = $self->_check_args( \@_, ['voltage'] );
89 return $self->set_level( $voltage, $tail );
90 }
91  
92 sub get_level {
93 my $self = shift;
94  
95 return $self->{'device_cache'}->{'level'};
96 }
97  
98 sub active {
99 return 0;
100 }
101  
102 sub abort {
103 return 0;
104 }
105  
106 sub set_range {
107 my $self = shift;
108 my $range = shift;
109 my $args = {@_};
110 my $channel = $args->{'channel'} || $self->default_channel();
111  
112 my $tmp = "last_range_$channel";
113 $self->{$tmp} = $range;
114 print "DS: setting virtual range of channel $channel to $range\n";
115 }
116  
117 sub get_range {
118 my $self = shift;
119 my $args = {@_};
120 my $channel = $args->{'channel'} || $self->default_channel();
121  
122 my $tmp = "last_range_$channel";
123 print "DS: getting virtual range: $$self{$tmp}\n";
124 return $self->{$tmp};
125 }
126  
127 1;
128  
129 __END__