@@ -44,6 +44,7 @@ class ControllerInterface:
44
44
__metaclass__ = ABCMeta
45
45
46
46
loop_map = []
47
+ named_loop_map = {}
47
48
48
49
def init_common (self , ** kwargs ):
49
50
'''Setup properties of all controllers of the chamberconnectlibrary'''
@@ -99,16 +100,35 @@ def set_refrig(self, value):
99
100
pass
100
101
101
102
@exclusive
102
- def get_loop (self , N , loop_type , param_list = None ):
103
+ def get_loop (self , identifier , * args ):
103
104
'''
104
105
Get all parameters for a loop from a given list.
105
-
106
- Args:
107
- N (int): The loop number (1-4).
108
- loop_type (str): The loop type::
109
- "cascade" -- A cascade control loop.
110
- "loop" -- A standard control loop.
111
- param_list (list(str)): The list of parameters to read defaults::
106
+ There are four different ways to call this method; all methods return the same data:
107
+
108
+ get_loop(str(identifier), *str(parameters))
109
+ Args:
110
+ identifier (str): The name of the loop.
111
+ parameters (list(string)): The list of parameters to get from the loop, (see below)
112
+
113
+ get_loop(str(identifier), [str(parameters)])
114
+ Args:
115
+ identifier (str): The name of the loop.
116
+ parameters (list(string)): The list of parameters to get from the loop, (see below)
117
+
118
+ get_loop(int(identifier), str(loop_type), *str(parameters))
119
+ Args:
120
+ identifier (str): The name of the loop.
121
+ loop_type (str): The type of loop to be accessed ("loop" or "cascade")
122
+ parameters (list(string)): The list of parameters to get from the loop, (see below)
123
+
124
+ get_loop(int(identifier), str(loop_type), [str(parameters)])
125
+ Args:
126
+ identifier (str): The name of the loop.
127
+ loop_type (str): The type of loop to be accessed ("loop" or "cascade")
128
+ parameters (list(string)): The list of parameters to get from the loop, (see below)
129
+
130
+ parameters:
131
+ The following is a list of available parameters as referenced by each call type:
112
132
"setpoint" -- The target temp/humi/altitude/etc of the control loop
113
133
"processvalue" -- The current conditions inside the chamber
114
134
"range" -- The settable range for the "setpoint"
@@ -158,41 +178,62 @@ def get_loop(self, N, loop_type, param_list=None):
158
178
'power' :self .get_loop_power
159
179
}
160
180
}
181
+
182
+ if isinstance (identifier , basestring ):
183
+ my_loop_map = self .loop_map [self .named_loop_map [identifier ]]
184
+ loop_number = my_loop_map ['num' ]
185
+ loop_type = my_loop_map ['type' ]
186
+ param_list = args if len (args ) > 0 else None
187
+ elif isinstance (identifier , int ) and len (args ) >= 1 :
188
+ loop_number = identifier
189
+ loop_type = args [0 ]
190
+ param_list = args [1 :] if len (args ) > 1 else None
191
+ else :
192
+ raise ValueError (
193
+ 'invalid argument format, call w/: '
194
+ 'get_loop(int(identifier), str(loop_type), *args) or '
195
+ 'get_loop(str(identifier), *args), *args are optional.'
196
+ )
197
+
161
198
if param_list is None :
162
199
param_list = loop_functions [loop_type ].keys ()
163
200
excludes = ['setPoint' , 'setValue' , 'processValue' ]
164
201
param_list = [x for x in param_list if x not in excludes ]
202
+ elif len (param_list ) >= 1 and \
203
+ (isinstance (param_list [0 ], list ) or isinstance (param_list [0 ], tuple )):
204
+ param_list = param_list [0 ]
165
205
ret = {}
166
206
for key in param_list :
167
207
try :
168
- ret [key ] = loop_functions [loop_type ][key ](N , exclusive = False )
208
+ ret [key ] = loop_functions [loop_type ][key ](loop_number , exclusive = False )
169
209
except KeyError :
170
210
ret [key ] = None
171
211
except NotImplementedError :
172
212
ret [key ] = None
173
213
return ret
174
214
175
215
@exclusive
176
- def set_loop (self , N , loop_type , param_list ):
216
+ def set_loop (self , identifier , loop_type = 'loop' , param_list = None , ** kwargs ):
177
217
'''
178
218
Set all parameters for a loop from a given list.
179
219
180
220
Args:
181
- N (int): The loop number (1-4).
182
- loop_type (str): The loop type::
221
+ identifier (int or str ): The loop number, or the name of the loop
222
+ loop_type (str): The loop type (disregarded when identifier is a str) ::
183
223
"cascade" -- A cascade control loop.
184
- "loop" -- A standard control loop.
185
- param_list (dict(dict)): The possible keys and there values::
224
+ "loop" -- A standard control loop (default).
225
+ param_list (dict(dict)): The parameters to update as a dictionary::
226
+ see kwargs for possible keys/values
227
+ kwargs (dict): The parameters to update as key word arguments, param_list overrides::
186
228
"setpoint" -- The target temp/humi/altitude/etc of the control loop
187
229
"range" -- The settable range for the "setpoint"
188
230
"enable" -- turn the control loop on or off
189
231
"power" -- set the manual power of the control loop
232
+ "mode" -- set the control mode of the control loop
190
233
"deviation" -- (type="cascade" only) The allowable difference between air/prod.
191
234
"enable_cascade" -- (type="cascade" only) Enable or disable cascade type control
192
235
Returns:
193
236
None
194
- Raises:
195
- ModbusError
196
237
'''
197
238
loop_functions = {
198
239
'cascade' :{
@@ -216,14 +257,39 @@ def set_loop(self, N, loop_type, param_list):
216
257
'power' :self .set_loop_power
217
258
}
218
259
}
260
+ if param_list is None :
261
+ param_list = kwargs
262
+ if isinstance (identifier , basestring ):
263
+ my_loop_map = self .loop_map [self .named_loop_map [identifier ]]
264
+ loop_number = my_loop_map ['num' ]
265
+ loop_type = my_loop_map ['type' ]
266
+ elif isinstance (identifier , int ):
267
+ loop_number = identifier
268
+ else :
269
+ raise ValueError (
270
+ 'invalid argument format, call w/: '
271
+ 'set_loop(int(identifier), str(loop_type), **kwargs) or '
272
+ 'get_loop(str(identifier), **kwargs)'
273
+ )
274
+
219
275
#mode must be done first
220
276
if 'mode' in param_list :
221
- loop_functions [loop_type ]['mode' ](exclusive = False , N = N , value = param_list .pop ('mode' ))
277
+ loop_functions [loop_type ]['mode' ](
278
+ exclusive = False ,
279
+ N = loop_number ,
280
+ value = param_list .pop ('mode' )
281
+ )
222
282
for key , val in param_list .items ():
223
283
try :
224
- loop_functions [loop_type ][key ](exclusive = False , N = N , value = val )
284
+ loop_functions [loop_type ][key ](
285
+ exclusive = False ,
286
+ N = loop_number ,
287
+ value = val
288
+ )
225
289
except KeyError :
226
290
pass
291
+ except NotImplementedError :
292
+ pass
227
293
228
294
@exclusive
229
295
def get_operation (self , pgm = None ):
@@ -341,7 +407,7 @@ def set_program(self, N, value):
341
407
342
408
Args:
343
409
N (int): The program number
344
- value (dict): The program to write to the controller
410
+ value (dict): The program to write to the controller, None erases the given program
345
411
'''
346
412
if value is None :
347
413
return self .prgm_delete (N , exclusive = False )
@@ -996,6 +1062,15 @@ def set_network_settings(self, value):
996
1062
'''
997
1063
pass
998
1064
1065
+ def get_operation_modes (self ):
1066
+ '''
1067
+ Get the supported operation modes for this controller.
1068
+
1069
+ Returns:
1070
+ ["standby","constant","program"] or ["constant","program"]
1071
+ '''
1072
+ return ['standby' , 'constant' , 'program' ]
1073
+
999
1074
def self_test (self , loops , cascades ):
1000
1075
'''
1001
1076
preform a self test on all functions
0 commit comments