-
Notifications
You must be signed in to change notification settings - Fork 3
/
temperature_BF.py
147 lines (120 loc) · 3.82 KB
/
temperature_BF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Copyright []
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#This grabs the latest temperatures from the log file on the Z:/drive, it is
# very specific to the Bluefors dilfridge
#
"""
### BEGIN NODE INFO
[info]
name = temperature_BF
version = 1.0
description = Grabbing temperature from a log file on the Z drive
[startup]
cmdline = %PYTHON% %FILE%
timeout = 20
[shutdown]
message = 987654321
timeout = 20
### END NODE INFO
"""
import platform
# global serial_server_name
# serial_server_name = platform.node() + '_serial_server'
from labrad.server import setting
from labrad.devices import DeviceServer,DeviceWrapper
from twisted.internet.defer import inlineCallbacks, returnValue
import labrad.units as units
from labrad.types import Value
import numpy as np
import os, fnmatch, datetime, time, shutil
CH = ['CH1','CH2','CH3','CH5','CH6','CH9']
NAMES = ['50 K Stage','4 K Stage','Magnet','Still','Mixing Chamber','Probe']
LOG_DIR = 'Z:\Fridge Logs\BLUEFORS T\\'
class serverInfo(object):
def __init__(self):
self.deviceName = 'Temperature_BF'
self.serverName = "temperature_BF"
self.fnames = {}
def getDeviceName(self,comPort):
return "temperature_BF"
class TemperatureBFWrapper(DeviceWrapper):
@inlineCallbacks
def connect(self, server, port):
"""Connect to a device."""
os.chdir(LOG_DIR)
def shutdown(self):
"""Disconnect from the serial port when we shut down."""
pass
class TemperatureBFServer(DeviceServer):
name = 'temperature_BF'
deviceName = 'Temperature_BF'
deviceWrapper = TemperatureBFWrapper
@setting(100)
def connect(self,c,server,port):
dev=self.selectedDevice(c)
yield dev.connect(server,port)
@setting(101)
def update_dir(self,c):
os.chdir(LOG_DIR)
curr_dir = os.listdir('.')[-1]
os.chdir(curr_dir)
files = os.listdir('.')
fnames = {}
for fi in files:
for fn in CH:
if fnmatch.fnmatch(fi,fn+' T*'):
fnames[fn] = fi
self.fnames = fnames
@setting(102, returns='*v[]')
def get_latest(self,c):
self.update_dir(self)
files = os.listdir('.')
Ts = np.zeros(len(CH))
t = '0'
for i in range(len(CH)):
key = CH[i]
if self.fnames.has_key(key):
fi = open(self.fnames[key],'r')
ln = fi.readlines()[-1]
T = yield self.grab_Ts(c,ln)
Ts[i]= T
yield Ts
returnValue(Ts)
@setting(103,line='s',returns='*v')
def grab_Ts(self,c,line):
vals = line.strip().split(",");
date = vals[0]
tm = vals[1]
T = float(vals[2])
dt = datetime.datetime.strptime(date+','+tm,'%d-%m-%y,%X')
t = dt.strftime('%Y-%m-%d %H:%M:%S.%f')
return T
@setting(104,returns='v[]')
def probe(self,c):
Ts = yield self.get_latest(c)
T = Ts[-1]
yield T
returnValue(T)
@setting(105,returns='v[]')
def mc(self,c):
Ts = yield self.get_latest(c)
T = Ts[-2]
yield T
returnValue(T)
__server__ = TemperatureBFServer()
if __name__ == '__main__':
from labrad import util
util.runServer(__server__)