importcopyimportjsonimporttimefromchamberconnectlibrary.watlowf4timportWatlowF4T#connect to our controller, update 'interface_params' as needed.interface_params={'interface':'TCP','host':'10.30.200.254'}controller=WatlowF4T(alarms=8,# the number of available alarmsprofiles=True,# the controller has programmingloops=1,# the number of control loops (ie temperature)cond_event=9,# the event that enables/disables conditioningcond_event_toggle=False,# is the condition momentary(False), or maintained(True)run_module=1,# The io module that has the chamber run outputrun_io=1,# The run output on the mdoule that has the chamber run out putlimits=[5],# A list of modules that contain limit type cards.**interface_params)defdeep_update(target,updates):"""Update the step_template with our data. This is targeted specifically for what we are doing here; don't reuse with significant testing. """fork,vinupdates.items():ifisinstance(v,dict):target[k]=deep_update(target[k],v)elifisinstance(v,list):fori,uinenumerate(v):ifisinstance(u,dict):target[k][i]=deep_update(target[k][i],u)else:target[k][i]=uelse:target[k]=vreturntarget# Program data to use to update our template.program_slot=2# This is the where we will save the program.program_name='WDTEST'# It is best practice to give the program a namesteps=[{'type':'ramptime','duration':{'seconds':1},'loops':[{'target':20.0}]},# Initialize to 20C{'type':'soak','duration':{'seconds':1},'loops':[{'gsoak':True}]},# Wait for the chamber to get to temperature# duration[minutes] is calculated as |start_time-end_time|/change_rate#{'type':'ramptime', 'duration':{'minutes':abs(30.0-20.0)/2.0}, 'loops':[{'target':30.0}]}, #ramptime at 2.0C/min{'type':'ramprate','loops':[{'target':30.0,'rate':2.0}]},# ramprate at 2.0C/min# {'type':'end', 'loops':[{'mode':'hold'}]} # The F4T does not require an end step. note: must set the 'loops':[{'mode':''}] "hold" or "user"]print'Get template from the controller'template=controller.get_prgm(0)step_template=template['steps'][0]# The WatlowF4T template seems to be wrong...foreinstep_template['events']:e['value']='off'# Start to modify our template into the final program.template['steps']=[]# remove step templatetemplate['name']=program_name# It is best practice to give the program a nametemplate["gs_dev"][0]['value']=0.5forstepinsteps:mystep=copy.deepcopy(step_template)# copy the template (python objects are by reference)deep_update(mystep,step)# update the copied steptemplate['steps'].append(mystep)# insert the step into our template# save the program to a file so we may review it.# with open('test.json', 'w') as f:# json.dump(template, f, indent=4, sort_keys=True)print'Save program to controller program slot #%d'%program_slotcontroller.set_prgm(program_slot,template)# Remove the exit(0) to start the program and monitor it.# I don't want to accidentally cause any problems with your chambers.exit(0)controller.set_operation('program',program=program_slot)print'Monitor the program'whileTrue:# emulate a do while loopstatus=controller.get_operation(template)setpoint=controller.get_loop(1,'loop','setpoint')['setpoint']ifstatus['status']!='Program Running':# emulate a do while loopbreakprint'temp setpoint: %sC'%setpoint['current']print'%s, Time Remaining: %s\n'%(status['status'],status['program']['time_remaining'])time.sleep(3)
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.