Instrument/TCD.pm

filter: Statementstmt 19.6% 12 / 61 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 33.3% 3 / 9 Podpod 66.6% 4 / 6 totaltotal 14.6% 19 / 130 SCAR 55.9
CC
19
Cov
12%
get_T
342.0
new
6.0
get_value
2.0
CRAP 268.0
« Moose/Instrument/OI_ITC503.pm ↑ Summary Bus/DEBUG.pm »
1 package Lab::Instrument::TCD;
2 #ABSTRACT: Temperature control for our Oxford Instruments TLM dilution fridge
3 1 $Lab::Instrument::TCD::VERSION = '3.881';
4 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Lab::Instrument;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our @ISA = ("Lab::Instrument");
10  
11 1 our %fields = (
12 supported_connections => [ 'VISA_RS232', 'RS232', 'IsoBus', 'DEBUG' ],
13  
14 connection_settings => {
15 baudrate => 9600,
16 databits => 8,
17 stopbits => 1,
18 parity => 'none',
19 handshake => 'none',
20  
21 #rs232_echo => 'character',
22 termchar => "\r",
23 timeout => 1
24 },
25  
26 device_settings => { read_default => 'device' },
27  
28 device_cache => {
29 id => 'Temperature Control',
30  
31 #T => undef
32 }
33  
34 );
35  
36 sub new {
37 0 ▶ my $proto = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
38 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
39 0 my $self = $class->SUPER::new(@_);
40 0 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
41  
42 0 return $self;
43 }
44  
45 sub get_value {
46 0 ▶ my $self = shift;
Subroutine get_value: not called CC=1 SCAR=6.9
Pod undocumented
47 0 return $self->get_T(@_);
48 }
49  
50 sub get_T {
51 0 ▶ my $self = shift;
Subroutine get_T: not called CC=18 SCAR=58.3
Pod documented
52 0 my ($read_mode) = $self->_check_args( \@_, ['read_mode'] );
53 0 my $temperature = "xxxxxxxx";
54  
55 0 ▶ if ( not defined $read_mode
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $read_mode and $read_mode =~ /device|cache|request|fetch/u) 0 0 0
Condition0%0/3
defined $read_mode and $read_mode =~ /device|cache|request|fetch/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $read_mode and $read_mode =~ /device|cache|request|fetch/u
defined $read_mode $read_mode =~ /device|cache|request|fetch/u
Truth table0%0/3
A and B
A= defined $read_modeB= $read_mode =~ /device|cache|request|fetch/u
ABresult
0X0
100
111
56 or not $read_mode =~ /device|cache|request|fetch/ ) {
57 0 $read_mode = $self->device_settings()->{read_default};
58 }
59  
60 0 ▶ if ( $read_mode eq 'cache' and defined $self->{'device_cache'}->{'T'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($read_mode eq 'cache' and defined $self->{'device_cache'}{'T'}) { } 0 0 0
elsif ($read_mode eq 'request') { } 0 0 0
elsif ($read_mode eq 'fetch' and $self->{'request'} == 1) { } 0 0 0
Condition0%0/3
$read_mode eq "cache" and defined $self->{"device_cache"}{"T"}
!ll&&!rl&&r
000
MC/DC0%0/2
$read_mode eq "cache" and defined $self->{"device_cache"}{"T"}
$read_mode eq "cache" defined $self->{"device_cache"}{"T"}
Truth table0%0/3
A and B
A= $read_mode eq "cache"B= defined $self->{"device_cache"}{"T"}
ABresult
0X0
100
111
61 0 return $self->{'device_cache'}->{'T'};
62 }
63 elsif ( $read_mode eq 'request' ) {
64 0 ▶ if ( $self->{'request'} != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"request"} != 0) 0 0 0
65 0 eval "$self->read();";
66 }
67 0 ▶ while ( ( $self->write("getTemp\r\n") < 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->write("getTemp\r\n") < 0) 0 0 0
68  
69 #print "repeat sending\n";
70 }
71 0 $self->{'request'} = 1;
72 }
73 ▶ elsif ( $read_mode eq 'fetch' and $self->{'request'} == 1 ) {
Condition0%0/3
$read_mode eq "fetch" and $self->{"request"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$read_mode eq "fetch" and $self->{"request"} == 1
$read_mode eq "fetch" $self->{"request"} == 1
Truth table0%0/3
A and B
A= $read_mode eq "fetch"B= $self->{"request"} == 1
ABresult
0X0
100
111
74 0 $self->{'request'} = 0;
75  
76 0 my $temperature;
77 0 while (1) {
78 0 eval '$temperature = $self->read()';
79 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif ($temperature < 0 or $temperature > 1.5) { } 0 0 0
80 0 next;
81 }
82 ▶ elsif ( $temperature < 0 or $temperature > 1.5 ) {
Condition0%0/3
$temperature < 0 or $temperature > "1.5"
l!l&&r!l&&!r
000
MC/DC0%0/2
$temperature < 0 or $temperature > "1.5"
$temperature < 0 $temperature > "1.5"
Truth table0%0/3
A or B
A= $temperature < 0B= $temperature > "1.5"
ABresult
1X1
011
000
83  
84 #print "from cache";
85 0 return $self->{'device_cache'}->{'T'};
86 }
87 else {
88 0 chomp $temperature;
89 0 $self->{'device_cache'}->{'T'} = $temperature;
90 0 return $self->{'device_cache'}->{'T'};
91 }
92 }
93  
94 }
95  
96 else {
97 0 ▶ for ( my $i = 0; $i < 3; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 3) 0 0 0
98 0 $self->write("getTemp\r\n");
99  
100 0 ▶ for ( my $j = 0; $j < 3; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < 3) 0 0 0
101 0 eval '$temperature = $self->read()';
102 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif ($temperature < 0 or $temperature > 1.5) { } 0 0 0
103 0 next;
104 }
105 ▶ elsif ( $temperature < 0 or $temperature > 1.5 ) {
Condition0%0/3
$temperature < 0 or $temperature > "1.5"
l!l&&r!l&&!r
000
MC/DC0%0/2
$temperature < 0 or $temperature > "1.5"
$temperature < 0 $temperature > "1.5"
Truth table0%0/3
A or B
A= $temperature < 0B= $temperature > "1.5"
ABresult
1X1
011
000
106  
107 #print "from cache";
108 0 return $self->{'device_cache'}->{'T'};
109 }
110 else {
111 0 chomp $temperature;
112 0 $self->{'device_cache'}->{'T'} = $temperature;
113 0 return $self->{'device_cache'}->{'T'};
114 }
115 }
116  
117 }
118  
119 0 return $self->{'device_cache'}->{'T'};
120 }
121  
122 }
123  
124 sub set_T {
125 0 ▶ my $self = shift;
Subroutine set_T: not called CC=1 SCAR=6.9
Pod documented
126 0 my ($temperature) = $self->_check_args( \@_, ['temperaure'] );
127  
128 0 my $temp = $self->query("setTemp\r\n$temperature\r\n");
129  
130 0 chomp $temp;
131  
132 #sleep(1);
133  
134 0 return $temp;
135 }
136  
137 sub set_heateroff {
138 0 ▶ my $self = shift;
Subroutine set_heateroff: not called CC=1 SCAR=6.9
Pod documented
139  
140 0 $self->write("heaterOff\r\n");
141  
142 }
143  
144 sub set_heatercontrol {
145 0 ▶ my $self = shift;
Subroutine set_heatercontrol: not called CC=1 SCAR=6.9
Pod undocumented
146  
147 0 return;
148 }
149  
150 # sub stabilize_T {
151 # my $self = shift;
152 # my $external_sensor = shift;
153  
154 # my $T = $self->get_T();
155 # my $Idc = $external_sensor->get_value();
156  
157 # push(@{$self->{data_buffer_T}}, $T);
158 # push(@{$self->{data_buffer_Idc}}, $Idc);
159  
160 # @{$self->{data_buffer_T}}= sort(@{$self->{data_buffer_T}});
161 # @{$self->{data_buffer_Idc}} = sort(@{$self->{data_buffer_Idc}});
162  
163 # my $length = @{$self->{data_buffer_T}};
164  
165 # my $median_T = @{$self->{data_buffer_T}}[$length/2];
166 # my $median_Idc = @{$self->{data_buffer_Idc}}[$length/2];
167  
168 # my $range_T = abs(@{$self->{data_buffer_T}}[-1]-@{$self->{data_buffer_T}}[0]);
169 # my $range_Idc = abs(@{$self->{data_buffer_Idc}}[-1]-@{$self->{data_buffer_Idc}}[0]);
170  
171 # print "Legth of buffer = $length\n";
172 # print "Median T = $median_T\n";
173 # print "Range T = $range_T\n";
174 # print "Median Idc = $median_Idc\n";
175 # print "Range Idc = $range_Idc\n";
176 # print "\n";
177 # print "T = $T\n";
178 # print "Idc = $Idc\n";
179  
180 # if ( $length > 30 )
181 # {
182 # #print abs($median_T - @{$self->{data_buffer_T}}[-1])." ?= ".(0.01*$range_T)."\n";
183 # if ( $range_T <= abs(0.05*$T) )
184 # {
185 # print "T stable\n";
186 # if ( $range_Idc <= abs(0.01*$Idc) )
187 # {
188 # print "Idc stable\n";
189 # return 0;
190 # }
191 # return 1;
192 # }
193  
194 # shift @{$self->{data_buffer_T}};
195 # shift @{$self->{data_buffer_Idc}};
196 # }
197  
198 # print "===============================\n\n\n";
199  
200 # return 1;
201  
202 # }
203  
204 1 1;
205  
206 __END__
207  
208 =pod
209  
210 =encoding UTF-8
211  
212 =head1 NAME
213  
214 Lab::Instrument::TCD - Temperature control for our Oxford Instruments TLM dilution fridge
215  
216 =head1 VERSION
217  
218 version 3.881
219  
220 =head1 SYNOPSIS
221  
222 use Lab::Instrument::RS232;
223 my $rs232=new Lab::Instrument::RS232();
224  
225 use Lab::Instrument::TCD;
226 my $tcd=new Lab::Instrument::TCD($rs232,$addr);
227  
228 =head1 DESCRIPTION
229  
230 The Lab::Instrument::ITC class implements an interface to our Oxford Dilution Fridge
231  
232 =head1 CONSTRUCTOR
233  
234 my $tcd=new Lab::Instrument::TCD($rs232,$addr);
235  
236 Instantiates a new object attached to the RS232 port.
237  
238 =head1 METHODS
239  
240 =head2 get_T
241  
242 $temperature=$tcd->get_T();
243  
244 Returns the current temperature of the mixing chamber.
245  
246 =head2 set_T
247  
248 $temperature=$tcd->set_T($temperature);
249  
250 Set target value for the temperature control circuit.
251  
252 =over 4
253  
254 =item $temperature
255  
256 TEMPERATURE can be between 0 ... 1 K.
257  
258 =back
259  
260 =head2 set_heateroff
261  
262 $temperature=$tcd->set_heateroff();
263  
264 Switch OFF the heater for the mixing chamber
265  
266 =head1 CAVEATS/BUGS
267  
268 probably many
269  
270 =head1 SEE ALSO
271  
272 =over 4
273  
274 =item L<Lab::Instrument>
275  
276 =back
277  
278 =head1 COPYRIGHT AND LICENSE
279  
280 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
281  
282 Copyright 2013 Christian Butschkow
283 2016 Simon Reinhardt
284 2017 Andreas K. Huettel
285 2020 Andreas K. Huettel
286  
287  
288 This is free software; you can redistribute it and/or modify it under
289 the same terms as the Perl 5 programming language system itself.
290  
291 =cut
« Moose/Instrument/OI_ITC503.pm ↑ Summary Bus/DEBUG.pm »