53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
def get_puck_names():
|
|
return [str(a)+str(b) for a in BLOCKS for b in range(1,6)]
|
|
|
|
|
|
def get_puck_info(status=None):
|
|
ret = []
|
|
#for puck in get_puck_names():
|
|
for puck in BasePlate.pucks:
|
|
if (status is None) or (status==puck.status):
|
|
ret.append({"address" : str(puck.name), "status": str(puck.status), "barcode" : str(puck.id)})
|
|
return ret
|
|
|
|
|
|
def get_puck_obj(address):
|
|
return BasePlate.getChild(address)
|
|
|
|
|
|
def get_puck_obj_by_id(puck_id):
|
|
if puck_id:
|
|
for puck in BasePlate.pucks:
|
|
if puck.id == puck_id:
|
|
return puck
|
|
return None
|
|
|
|
|
|
def set_puck_info(puck_info):
|
|
#print puck_info
|
|
for i in puck_info:
|
|
p=get_puck_obj(i["address"])
|
|
if p is not None:
|
|
if (p.status == 'Present') and ( i["status"] =='Present'):
|
|
if i['barcode'] and (i['barcode'] != str(None)):
|
|
#print "Setting ", p, " to ", i['barcode']
|
|
p.id = i['barcode']
|
|
|
|
def clear_puck_info():
|
|
save_puck_info([])
|
|
|
|
def save_puck_info():
|
|
data = get_puck_info()
|
|
output_file = open( Setup.expandPath("{context}/pucks_info.json") , "w")
|
|
output_file.write(json.dumps(data))
|
|
output_file.close()
|
|
|
|
def restore_puck_info():
|
|
try:
|
|
inputfile = open(Setup.expandPath("{context}/pucks_info.json"), "r")
|
|
info = json.loads(inputfile.read())
|
|
except:
|
|
print >> sys.stderr, "Error reading pucks info file: " + str(sys.exc_info()[1])
|
|
info = []
|
|
set_puck_info(info)
|
|
|