Snippets

Espec North America Watlow F4T program example

Created by Myles Metzler last modified
import copy 
import json
import time
from chamberconnectlibrary.watlowf4t import WatlowF4T

#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 alarms
    profiles=True, # the controller has programming
    loops=1, # the number of control loops (ie temperature)
    cond_event=9, # the event that enables/disables conditioning
    cond_event_toggle=False, # is the condition momentary(False), or maintained(True)
    run_module=1, # The io module that has the chamber run output
    run_io=1, # The run output on the mdoule that has the chamber run out put
    limits=[5], # A list of modules that contain limit type cards.
    **interface_params
)

def deep_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.
    """
    for k, v in updates.items():
        if isinstance(v, dict):
            target[k] = deep_update(target[k], v)
        elif isinstance(v, list):
            for i, u in enumerate(v):
                if isinstance(u, dict):
                    target[k][i] = deep_update(target[k][i], u)
                else:
                    target[k][i] = u
        else:
            target[k] = v
    return target


# 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 name
steps = [
    {'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...
for e in step_template['events']:
    e['value'] = 'off'

# Start to modify our template into the final program.
template['steps'] = [] # remove step template
template['name'] = program_name # It is best practice to give the program a name
template["gs_dev"][0]['value'] = 0.5
for step in steps:
    mystep = copy.deepcopy(step_template) # copy the template (python objects are by reference)
    deep_update(mystep, step) # update the copied step
    template['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_slot
controller.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'
while True: # emulate a do while loop
    status = controller.get_operation(template)
    setpoint = controller.get_loop(1, 'loop', 'setpoint')['setpoint']
    if status['status'] != 'Program Running': # emulate a do while loop
        break
    print 'temp setpoint: %sC' % setpoint['current']
    print '%s, Time Remaining: %s\n' % (status['status'], status['program']['time_remaining'])
    time.sleep(3)


Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.