line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sunpower::Cryocooler; |
2
|
1
|
|
|
1
|
|
23740
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use base 'Exporter'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
179
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.1.5'; |
6
|
|
|
|
|
|
|
our @EXPORT = qw(devwrite endscon gct gcm scm gtt stt gcs scs gcl); |
7
|
|
|
|
|
|
|
#################### |
8
|
|
|
|
|
|
|
### OS Dependant ### |
9
|
|
|
|
|
|
|
#################### |
10
|
|
|
|
|
|
|
BEGIN { |
11
|
1
|
|
|
1
|
|
933
|
require autouse; |
12
|
1
|
50
|
|
|
|
863
|
autouse->import( |
13
|
|
|
|
|
|
|
$^O =~ /^win32/i ? "Win32::SerialPort" : "Device::SerialPort" |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
######################## |
17
|
|
|
|
|
|
|
### End OS Dependant ### |
18
|
|
|
|
|
|
|
######################## |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Sunpower::Cryocooler - a module for interfacing with Sunpower Cryocoolers |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Sunpower::Cryocooler; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 REQUIRES |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Requires Device::SerialPort or Win32::SerialPort depending on platform. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Function library for interfacing with Sunpower Cryogenic Pumps |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 AUTHOR/LICENSE |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Perl Module Sunpower::Cryocooler - Library of functions for Sunpower cryogenic pumps. |
39
|
|
|
|
|
|
|
Copyright (C) 2009 Stanford University, Authored by Sam Kerr kerr@cpan.org |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
42
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
43
|
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or |
44
|
|
|
|
|
|
|
(at your option) any later version. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
47
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
48
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
49
|
|
|
|
|
|
|
GNU General Public License for more details. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
52
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software |
53
|
|
|
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 Functions |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
10 Functions exported by default: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
gct() |
61
|
|
|
|
|
|
|
gcm() |
62
|
|
|
|
|
|
|
scm() |
63
|
|
|
|
|
|
|
gtt() |
64
|
|
|
|
|
|
|
stt() |
65
|
|
|
|
|
|
|
gcs() |
66
|
|
|
|
|
|
|
scs() |
67
|
|
|
|
|
|
|
gcl() |
68
|
|
|
|
|
|
|
endscon() |
69
|
|
|
|
|
|
|
devwrite() |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head3 gct() - Get Current Temperature |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$temp = gct(); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head3 gcm() - Get Controller Mode |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$mode = gcm(); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head3 scm() - Set Controller Mode |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
scm($mode); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head3 gtt() - Get Target Temperature |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$tartemp = gtt(); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head3 stt() - Set Target Temperature |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
stt($tartemp); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head3 gcs() - Get Command Stroke |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$stroke = gcs(); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head3 scs() - Set Command Stroke |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
scs($stroke); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head3 gcl() - Get Command Stroke & Limits |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$limits = gcl(); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head3 endscon() - End Connection |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
&endscon; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head3 devwrite() - User Inputted Command Issuer |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
devwrite(@commands); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
-or- |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
devwrite |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 Changelog |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
04-02-09 - Modified to run on Win32 (experimental!) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#################### |
125
|
|
|
|
|
|
|
## INITIALIZATION ## |
126
|
|
|
|
|
|
|
#################### |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $device = "/dev/ttyS0"; |
129
|
|
|
|
|
|
|
my $serial = Device::SerialPort-> new($device, 1); |
130
|
|
|
|
|
|
|
die "Can't open serial port $serial: $^E\n" unless ($serial); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$serial->user_msg(0); |
133
|
|
|
|
|
|
|
$serial->databits(8); |
134
|
|
|
|
|
|
|
$serial->baudrate(4800); |
135
|
|
|
|
|
|
|
$serial->parity("none"); |
136
|
|
|
|
|
|
|
$serial->stopbits(1); |
137
|
|
|
|
|
|
|
$serial->handshake("none"); |
138
|
|
|
|
|
|
|
$serial->datatype('raw'); |
139
|
|
|
|
|
|
|
$serial->dtr_active('T'); |
140
|
|
|
|
|
|
|
$serial->stty_icrnl(0); |
141
|
|
|
|
|
|
|
$serial->write_settings; |
142
|
|
|
|
|
|
|
$serial->read_char_time(0); |
143
|
|
|
|
|
|
|
$serial->read_const_time(1000); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $STALL_DEFAULT=5; |
146
|
|
|
|
|
|
|
my $timeout=$STALL_DEFAULT; |
147
|
|
|
|
|
|
|
############## |
148
|
|
|
|
|
|
|
## END INIT ## |
149
|
|
|
|
|
|
|
############## |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub endscon{ |
152
|
0
|
|
|
0
|
|
|
$serial->close(); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
################################## |
157
|
|
|
|
|
|
|
## Developer Raw Command Issuer ## |
158
|
|
|
|
|
|
|
################################## |
159
|
|
|
|
|
|
|
sub devwrite{ |
160
|
0
|
|
|
0
|
|
|
my $inarg = shift(@_); |
161
|
0
|
0
|
|
|
|
|
if(!defined $inarg){ |
|
|
0
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
print "Input Command: "; |
163
|
0
|
|
|
|
|
|
$inarg = <>; |
164
|
0
|
|
|
|
|
|
print $serial -> write("$inarg\r"); |
165
|
0
|
|
|
|
|
|
my $devin; |
166
|
0
|
|
|
|
|
|
my $chars=0; |
167
|
0
|
|
|
|
|
|
my $buffer=""; |
168
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
169
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
171
|
0
|
|
|
|
|
|
$chars+=$count; |
172
|
0
|
|
|
|
|
|
$buffer.=$saw; |
173
|
0
|
|
|
|
|
|
$devin = $buffer; |
174
|
|
|
|
|
|
|
} |
175
|
0
|
|
|
|
|
|
return $devin; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
elsif(defined $inarg){ |
179
|
0
|
|
|
|
|
|
print $serial -> write("$inarg\r"); |
180
|
0
|
|
|
|
|
|
my $devin; |
181
|
0
|
|
|
|
|
|
my $chars=0; |
182
|
0
|
|
|
|
|
|
my $buffer=""; |
183
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
184
|
|
|
|
|
|
|
|
185
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
186
|
0
|
|
|
|
|
|
$chars+=$count; |
187
|
0
|
|
|
|
|
|
$buffer.=$saw; |
188
|
0
|
|
|
|
|
|
$devin = $buffer; |
189
|
|
|
|
|
|
|
} |
190
|
0
|
|
|
|
|
|
return $devin; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
############################# |
195
|
|
|
|
|
|
|
## BEGIN CRYO FUNCTION LIB ## |
196
|
|
|
|
|
|
|
############################# |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub gct{ |
199
|
|
|
|
|
|
|
#Get Current Temperature |
200
|
0
|
|
|
0
|
|
|
my $gct_in; |
201
|
0
|
|
|
|
|
|
print $serial->write("TC\r"); |
202
|
0
|
|
|
|
|
|
my $chars=0; |
203
|
0
|
|
|
|
|
|
my $buffer=""; |
204
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
205
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
206
|
0
|
|
|
|
|
|
$chars+=$count; |
207
|
0
|
|
|
|
|
|
$buffer.=$saw; |
208
|
0
|
|
|
|
|
|
$gct_in = $buffer; |
209
|
|
|
|
|
|
|
} |
210
|
0
|
|
|
|
|
|
$gct_in =~ m/(\w+)(\D+)(\d+\.\d)/; |
211
|
0
|
|
|
|
|
|
return $3; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub gcm{ |
215
|
|
|
|
|
|
|
#Get Controller Mode |
216
|
0
|
|
|
0
|
|
|
my $gcm_in; |
217
|
0
|
|
|
|
|
|
print $serial -> write("SET PID\r"); |
218
|
0
|
|
|
|
|
|
my $chars=0; |
219
|
0
|
|
|
|
|
|
my $buffer=""; |
220
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
221
|
|
|
|
|
|
|
|
222
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
223
|
0
|
|
|
|
|
|
$chars+=$count; |
224
|
0
|
|
|
|
|
|
$buffer.=$saw; |
225
|
0
|
|
|
|
|
|
$gcm_in = $buffer; |
226
|
|
|
|
|
|
|
} |
227
|
0
|
|
|
|
|
|
$gcm_in =~ m/(\w+)(\D+)(\d+\.\d)/; |
228
|
0
|
|
|
|
|
|
return $3; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub scm{ |
232
|
|
|
|
|
|
|
#Set Controller Mode |
233
|
0
|
|
|
0
|
|
|
my $input = shift(@_); |
234
|
0
|
0
|
|
|
|
|
if($input =~ m/[0,2]/) |
235
|
0
|
|
|
|
|
|
{ |
236
|
0
|
|
|
|
|
|
my $scm_in; |
237
|
0
|
|
|
|
|
|
print $serial -> write("SET PID=$input\r"); |
238
|
0
|
|
|
|
|
|
my $chars=0; |
239
|
0
|
|
|
|
|
|
my $buffer=""; |
240
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
241
|
|
|
|
|
|
|
|
242
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
243
|
0
|
|
|
|
|
|
$chars+=$count; |
244
|
0
|
|
|
|
|
|
$buffer.=$saw; |
245
|
0
|
|
|
|
|
|
$scm_in = $buffer; |
246
|
|
|
|
|
|
|
} |
247
|
0
|
|
|
|
|
|
$scm_in =~ m/(\w+)(\D+)(\d+\.\d)/; |
248
|
0
|
|
|
|
|
|
return $3; |
249
|
|
|
|
|
|
|
#return $scm_in; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
else{warn "Set Controller Mode can only be 0 or 2"; |
252
|
0
|
|
|
|
|
|
die "Controller Mode not 0 or 2\n"; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub gtt{ |
257
|
|
|
|
|
|
|
#Get Target Temperature |
258
|
0
|
|
|
0
|
|
|
my $gtt_in; |
259
|
0
|
|
|
|
|
|
print $serial -> write("SET TTARGET\r"); |
260
|
0
|
|
|
|
|
|
my $chars=0; |
261
|
0
|
|
|
|
|
|
my $buffer=""; |
262
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
263
|
|
|
|
|
|
|
|
264
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
265
|
0
|
|
|
|
|
|
$chars+=$count; |
266
|
0
|
|
|
|
|
|
$buffer.=$saw; |
267
|
0
|
|
|
|
|
|
$gtt_in = $buffer; |
268
|
|
|
|
|
|
|
} |
269
|
0
|
|
|
|
|
|
$gtt_in =~ m/(\w+)(\D+)(\d+\.\d)/; |
270
|
0
|
|
|
|
|
|
return $3; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub stt{ |
274
|
|
|
|
|
|
|
#Set Target Temperature (Mode 2) |
275
|
0
|
|
|
0
|
|
|
my $ttemp = shift(@_); |
276
|
0
|
0
|
0
|
|
|
|
if($ttemp > 10 && $ttemp < 300){ |
|
0
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
|
278
|
0
|
|
|
|
|
|
my $stt_in; |
279
|
0
|
|
|
|
|
|
print $serial -> write("SET TTARGET=$ttemp\r"); |
280
|
0
|
|
|
|
|
|
my $chars=0; |
281
|
0
|
|
|
|
|
|
my $buffer=""; |
282
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
283
|
|
|
|
|
|
|
|
284
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
285
|
0
|
|
|
|
|
|
$chars+=$count; |
286
|
0
|
|
|
|
|
|
$buffer.=$saw; |
287
|
0
|
|
|
|
|
|
$stt_in = $buffer; |
288
|
|
|
|
|
|
|
} |
289
|
0
|
|
|
|
|
|
$stt_in =~ m/(\w+)(\D+)(\d+\.\d)/; |
290
|
0
|
|
|
|
|
|
return $3; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
else{die "Target Temp must be between 60K and 100K\n |
293
|
|
|
|
|
|
|
Set Target Temp to between 60K and 100K\n";} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub gcs{ |
298
|
|
|
|
|
|
|
#Get Command Stroke (Mode 0) |
299
|
0
|
|
|
0
|
|
|
my $gcs_in; |
300
|
0
|
|
|
|
|
|
print $serial -> write("SET PWOUT\r"); |
301
|
0
|
|
|
|
|
|
my $chars=0; |
302
|
0
|
|
|
|
|
|
my $buffer=""; |
303
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
304
|
|
|
|
|
|
|
|
305
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
306
|
0
|
|
|
|
|
|
$chars+=$count; |
307
|
0
|
|
|
|
|
|
$buffer.=$saw; |
308
|
0
|
|
|
|
|
|
$gcs_in = $buffer; |
309
|
|
|
|
|
|
|
} |
310
|
0
|
|
|
|
|
|
$gcs_in =~ m/(\w+)(\D+)(\d+\.\d)/; |
311
|
0
|
|
|
|
|
|
return $3; |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
sub scs{ |
315
|
|
|
|
|
|
|
#Set Command Stroke (Mode 0) |
316
|
0
|
|
|
0
|
|
|
my $scs_in; |
317
|
0
|
|
|
|
|
|
my $strokin = shift(@_); |
318
|
0
|
0
|
|
|
|
|
if(defined $strokin){ |
|
0
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
## Code stroke limits ## |
320
|
0
|
|
|
|
|
|
print $serial -> write("SET PWOUT=$strokin\r"); |
321
|
0
|
|
|
|
|
|
my $chars=0; |
322
|
0
|
|
|
|
|
|
my $buffer=""; |
323
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
324
|
|
|
|
|
|
|
|
325
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
326
|
0
|
|
|
|
|
|
$chars+=$count; |
327
|
0
|
|
|
|
|
|
$buffer.=$saw; |
328
|
0
|
|
|
|
|
|
$scs_in = $buffer; |
329
|
|
|
|
|
|
|
} |
330
|
0
|
|
|
|
|
|
$scs_in =~ m/(\w+)(\D+)(\d+\.\d)/; |
331
|
0
|
|
|
|
|
|
return $3; |
332
|
|
|
|
|
|
|
} |
333
|
0
|
|
|
|
|
|
else{print "No set value given\n"; die;} |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
sub gcl{ |
337
|
|
|
|
|
|
|
#Get Command Stroke and Limits |
338
|
0
|
|
|
0
|
|
|
my $gcl_in; |
339
|
0
|
|
|
|
|
|
print $serial -> write("E\r"); |
340
|
0
|
|
|
|
|
|
my $chars=0; |
341
|
0
|
|
|
|
|
|
my $buffer=""; |
342
|
0
|
|
|
|
|
|
my ($count,$saw)=$serial->read(255); |
343
|
|
|
|
|
|
|
|
344
|
0
|
0
|
|
|
|
|
if ($count > 0) { |
345
|
0
|
|
|
|
|
|
$chars+=$count; |
346
|
0
|
|
|
|
|
|
$buffer.=$saw; |
347
|
0
|
|
|
|
|
|
$gcl_in = $buffer; |
348
|
|
|
|
|
|
|
} |
349
|
0
|
|
|
|
|
|
$gcl_in =~ s/^\w//g; |
350
|
0
|
|
|
|
|
|
return $gcl_in; |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
########################### |
354
|
|
|
|
|
|
|
## END CRYO FUNCTION LIB ## |
355
|
|
|
|
|
|
|
########################### |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
__END__ |