-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathedwards_nxds.py
More file actions
220 lines (199 loc) · 7.87 KB
/
edwards_nxds.py
File metadata and controls
220 lines (199 loc) · 7.87 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
""" Driver for Edwards, nXDS pumps """
import time
import logging
import serial
LOGGER = logging.getLogger(__name__)
LOGGER.addHandler(logging.NullHandler())
class EdwardsNxds(object):
""" Driver for the Edwards nXDS series of dry pumps """
def __init__(self, port):
self.ser = serial.Serial(port, 9600, timeout=2)
time.sleep(0.1)
def comm(self, command):
""" Ensures correct protocol for instrument """
self.ser.write((command + '\r').encode('ascii'))
return_string = self.ser.readline().decode()
if not return_string[2:5] == command[2:5]:
raise IOError
return return_string[6:-1]
def read_pump_type(self):
""" Read identification information """
return_string = self.comm('?S801')
pump_type = return_string.split(';')
return {
'type': pump_type[0],
'software': pump_type[1],
'nominal_frequency': pump_type[2],
}
def read_pump_temperature(self):
""" Read Pump Temperature """
return_string = self.comm('?V808')
temperatures = return_string.split(';')
pump = int(temperatures[0])
controller = int(temperatures[1])
return {'pump': pump, 'controller': controller}
def read_serial_numbers(self):
""" Read Pump Serial numbers """
return_string = self.comm('?S835')
service = return_string.split(';')
serials = service[0].split(' ')
return {
'Pump SNs': serials[0],
'drive-module SN': serials[1],
'PCA SN': serials[2],
'type': service[1].strip(),
}
def read_run_hours(self):
""" Return number of run hours """
return_string = self.comm('?V810')
run_hours = int(return_string)
return run_hours
def set_run_state(self, on_state):
""" Start or stop the pump """
if on_state is True:
return_string = self.comm('!C802 1')
else:
return_string = self.comm('!C802 0')
return return_string
def status_to_bin(self, word):
""" Convert status word to array of binaries """
status_word = ''
for i in range(0, 4):
val = int(word[i], 16)
status_word += bin(val)[2:].zfill(4)
bin_word = [False] * 16
for i in range(0, 15):
bin_word[i] = status_word[i] == '1'
return bin_word
def bearing_service(self):
""" Status of bearings """
return_string = self.comm('?V815')
status = return_string.split(';')
time_since = int(status[0])
time_to = int(status[1])
return {'time_since_service': time_since, 'time_to_service': time_to}
def pump_controller_status(self):
""" Read the status of the pump controller """
return_string = self.comm('?V813')
status = return_string.split(';')
controller_run_time = int(status[0])
time_to_service = int(status[1])
return {
'controller_run_time': controller_run_time,
'time_to_service': time_to_service,
}
def read_normal_speed_threshold(self):
""" Read the value for acknowledge the pump as normally running """
return_string = self.comm('?S804')
return int(return_string)
def read_standby_speed(self):
""" Read the procentage of full speed on standby """
return_string = self.comm('?S805')
return int(return_string)
def read_pump_status(self):
""" Read the overall status of the pump """
return_string = self.comm('?V802')
status = return_string.split(';')
rotational_speed = int(status[0])
system_status_1 = self.status_to_bin(status[1])
messages = []
if system_status_1[15] is True:
messages.append('Decelerating')
if system_status_1[14] is True:
messages.append('Running')
if system_status_1[13] is True:
messages.append('Standby Active')
if system_status_1[12] is True:
messages.append('Above normal Speed')
# if system_status_1[11] is True: # It is not entirely clear what this
# messages.append('Above ramp speed') # message means
if system_status_1[5] is True:
messages.append('Serial interface enabled')
system_status_2 = self.status_to_bin(status[2])
if system_status_2[15] is True:
messages.append('At power limit!')
if system_status_2[14] is True:
messages.append('Acceleration limited')
if system_status_2[13] is True:
messages.append('Deceleration limited')
if system_status_2[11] is True:
messages.append('Time for service!')
if system_status_2[9] is True:
messages.append('Warning')
if system_status_2[8] is True:
messages.append('Alarm')
warnings = []
warning_status = self.status_to_bin(status[3])
if warning_status[14] is True:
warnings.append('Temperature too low')
if warning_status[9] is True:
warnings.append('Pump too hot')
if warning_status[5] is True:
warnings.append('Temperature above maxumum measureable value')
if warning_status[0] is True:
warnings.append('EEPROM problem - service needed!')
faults = []
fault_status = self.status_to_bin(status[4])
if fault_status[14] is True:
faults.append('Voltage too high')
if fault_status[13] is True:
faults.append('Current too high')
if fault_status[12] is True:
faults.append('Temperature too high')
if fault_status[11] is True:
faults.append('Temperature sensor fault')
if fault_status[10] is True:
faults.append('Power stage failure')
if fault_status[7] is True:
faults.append('Hardware latch fault')
if fault_status[6] is True:
faults.append('EEPROM problem')
if fault_status[4] is True:
faults.append('No parameter set')
if fault_status[3] is True:
faults.append('Self test fault')
if fault_status[2] is True:
faults.append('Serial control interlock')
if fault_status[1] is True:
faults.append('Overload time out')
if fault_status[0] is True:
faults.append('Acceleration time out')
return {
'rotational_speed': rotational_speed,
'messages': messages,
'warnings': warnings,
'faults': faults,
}
def read_service_status(self):
""" Read the overall status of the pump """
service_status = self.status_to_bin(self.comm('?V826'))
messages = []
if service_status[15] is True:
messages.append('Tip seal service is due')
if service_status[14] is True:
messages.append('Bearing service is due')
if service_status[12] is True:
messages.append('Controller service is due')
if service_status[8] is True:
messages.append('Service is due')
return messages
def set_standby_mode(self, standbymode):
""" Set the pump on or off standby mode """
if standbymode is True:
return_string = self.comm('!C803 1')
else:
return_string = self.comm('!C803 0')
return return_string
if __name__ == '__main__':
PUMP = EdwardsNxds('/dev/ttyUSB3')
# print(PUMP.read_pump_type())
print(PUMP.read_pump_temperature())
# print(PUMP.read_serial_numbers())
# print(PUMP.read_run_hours())
# print(PUMP.read_normal_speed_threshold())
# print(PUMP.read_standby_speed())
# print(PUMP.pump_controller_status())
# print(PUMP.bearing_service())
# print(PUMP.read_pump_status()['rotational_speed'])
# print(PUMP.set_run_state(True))
# print(PUMP.set_standby_mode(False))