-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlLoopVCBFB.py
More file actions
157 lines (144 loc) · 3.52 KB
/
ControlLoopVCBFB.py
File metadata and controls
157 lines (144 loc) · 3.52 KB
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
148
149
150
151
152
153
154
155
156
157
import valvecontrol
import qweb
from datetime import datetime, timedelta
import time
import re
### dictionaries to map log file names to database names ###
# pairs are (local_name: loggable_name)
name_reference = {
'v11': None,
'v2': None,
'v1': None,
'turbo1': None,
'v12': None,
'v3': None,
'v10': None,
'turbo2': None,
'v14': None,
'v4': None,
'v13': None,
'compressor': None,
'v15': None,
'v5': None,
'hs-still': 'bfb_still_heatswitch',
'v21': None,
'v16': None,
'v6': None,
'scroll1': None,
'v22': None,
'v17': None,
'v7': None,
'scroll2': None,
'v23': None,
'v18': None,
'v8': None,
'pulsetube': None,
'v19': None,
'v20': None,
'v9': None,
'hs-mc': 'bfb_mc_heatswitch',
'ext': None,
'a1_u': None,
'a1_r_lead': None,
'a1_r_htr': None,
'a2_u': None,
'a2_r_lead': None,
'a2_r_htr': None,
'htr': None,
'htr_range': None,
'tc400errorcode': None,
'tc400ovtempelec': None,
'tc400ovtemppump': None,
'tc400setspdatt': None,
'tc400pumpaccel': None,
'tc400commerr': None,
'tc400errorcode_2': None,
'tc400ovtempelec_2': None,
'tc400ovtemppump_2': None,
'tc400setspdatt_2': None,
'tc400pumpaccel_2': None,
'tc400commerr_2': None,
'tvpower1': None,
'tvbearingtemp1': None,
'tvcontrollertemp1': None,
'tvbodytemp1': None,
'tvrot1': None,
'tvlife1': None,
'ctrl_pres': None,
'cpastate': None,
'cparun': None,
'cpawarn': None,
'cpaerr': None,
'cpatempwi': 'bfb_cmp_tempwi',
'cpatempwo': 'bfb_cmp_tempwo',
'cpatempo': 'bfb_cmp_tempo',
'cpatemph': None,
'cpalp': None,
'cpalpa': None,
'cpahp': None,
'cpahpa': None,
'cpadp': None,
'cpacurrent': None,
'cpahours': None,
'cpapscale': None,
'cpatscale': None,
'cpasn': None,
'cpamodel': None,
'flowmeter': 'bfb_flowmeter',
'P1': 'bfb_p1',
'P2': 'bfb_p2',
'P3': 'bfb_p3',
'P4': 'bfb_p4',
'P5': 'bfb_p5',
'P6': 'bfb_p6'
}
# pairs are (loggable_name: local_name)
inv_name_reference = {v: k for k, v in name_reference.items() if v}
### time constants ###
loop_time = 5.0 # seconds
### utility functions ###
def find_included_names(data):
""" take all log data read and return only those that have database entries """
global name_reference
loggable_data = []
for d in data:
if name_reference[d[1]]:
loggable_data.append(d)
return loggable_data
def find_loggable_data(data):
""" ask the server what needs to be updated. return just that list """
# get string from server describing which parameters need to be updated
global inv_name_reference
# string describing what needs to be updated
loggable_str = qweb.getLoggableInfoForNow('bfb')
# list of loggable_names to be updated
loggable_list = re.findall(r'loggable_name=(\w+);',loggable_str)
loggable_data = []
if loggable_list:
# get list of bluefors names from loggable_list using dictionary
lookup_list = [inv_name_reference[k] for k in loggable_list if k in inv_name_reference]
for d in data:
if d[1] in lookup_list:
loggable_data.append(d)
return loggable_data
def log_new_data(data):
""" push new database entries to the sql database using
the web service """
for d in data:
qweb.makeLogEntry(name_reference[d[1]], d[2])
### main loop below ###
if __name__ == "__main__":
vc = valvecontrol.ValveControlFromFile(r'C:\Users\folklab101\Desktop\logs')
# print(inv_name_reference)
while True:
try:
data = find_included_names(vc.read_all())
print('read all data...')
new_data = find_loggable_data(data)
if new_data:
print('logging new data...')
log_new_data(new_data)
print('new data logged! {0}'.format(str(datetime.now())))
except Exception as e:
print('ERROR: {0} at {1}'.format(e, str(datetime.now())))
time.sleep(loop_time)