def main(): _built_source_objs = {} o = bilt.Bilt() def _wrapper_function(func, *args): return getattr(o, func)(*args) def _make_lambda(func): def f(*args): return _wrapper_function(func, *args) return f import inspect import pynedm import time all_methods = inspect.getmembers(bilt.Bilt(), inspect.ismethod) def _create_function(aname): def _f(*args): o = bilt.Bilt() return getattr(o, aname)(*args) return _f def run_ramp(): def f(): _stop_run = False o = bilt.Bilt() pynedm.write_document_to_db({ "type" : "data", "value" : { "ramp_running" : 1 } }) o.run_ramp() while (int(o.read_macro_state()) == 2): time.sleep(1.) pynedm.write_document_to_db({ "type" : "data", "value" : { "ramp_running" : 0 } }) pynedm.start_process(f) alist = ['setup_ramp', 'read_macro_data', 'readallerrors', 'stop_macro'] adict = dict([(k, _create_function(k)) for k in alist]) adict['run_ramp'] = run_ramp for name, _ in all_methods: if name[:2] == '__': continue adict[name] = _make_lambda(name) print(adict) pyl = pynedm.listen(adict, "nedm%2Finternal_coils", username="******", password="******", uri="http://db.nedm1:5984") pyl.wait()
adamAO = adam_setter() adamAO_connected = False if adamAO.connect(adam_aoIP, adam_aoPort): adamAO_connected = True adamAO.set_ranges() adamAO.zero_all_ao() adio = webadio() adio_connected = False if adio.login(webadioIP, webadioPW): adio_connected = True dig_init() db_listener = pynedm.listen(execute_dict, _db username=_un, password=_pw, uri=_server) while True: adam_temps = adamT.read_temp() for Tname in adam_temps: adoc["value"][Tname] = float(adam_temps[Tname]) ls_values = lakesh.read_values() for key in ls_values: adoc["value"][key] = float(ls_values[key]) current = delta.read_current() state = delta.read_output_state()
time.sleep(5) # Stop the process adoc["execute"] = "stop_process" r = des.post("_update/insert_with_timestamp", params=adoc) print "Command: ", r.json() time.sleep(1) # Stop the program adoc["execute"] = "stop" r = des.post("_update/insert_with_timestamp", params=adoc) print "Command: ", r.json() if __name__ == '__main__': un = "username" pw = "password" db = "test" pynedm.listen({ "start_process" : start_process, "stop_process" : stop_process }, db, username=un, password=pw, verbose=True) import threading # Start control (normally run on another machine) t = threading.Thread(target=command_process, args=("http://127.0.0.1:5984", un, pw, db)) t.start() ####### pynedm.wait() t.join()
pynedm.start_process(f) return True def isrunning(): print("isrunning called") print(_dg.isrunning()) return _dg.isrunning() def interrupt_deg(): print("interrupt called") if not _dg.isrunning(): print("not in progress") raise Exception("Degaussing not in progress") _dg.interrupt_deg() adict = { "run_deg": run_deg, "isrunning": isrunning, "interrupt_deg": interrupt_deg } pylisten = pynedm.listen(adict, "nedm%2Fdegaussing", username="******", password="******", uri="http://raid.nedm1:5984", verbose=True) pylisten.wait() print "Finished"
global _running, _myprocess if _myprocess is not None: raise Exception("Measurement already running") _running = True _myprocess = pynedm.start_process(_measure) return True def stop_measure(): print "stop_measure" global _running, _myprocess if _myprocess is None: raise Exception("Measurement not running") _running = False retVal = _myprocess.result.get() _myprocess = None return retVal execute_dict = { "start_measure": start_measure, "stop_measure": stop_measure, "log_and_measure": log_and_measure } if __name__ == "__main__": pynedm.listen(execute_dict, "nedm%2Ffluxgate", username="******", password="******", uri = "http://raid.nedm1:5984") pynedm.wait()
"set_ramp_time" : set_ramp_time } adoc = { 'type':'data', 'value':{ 'pol_coil_current':0, 'trans_coil_current':0, 'guide_coil_current':0 } } pynedm.listen( db_func_dict, "nedm%2Fhexe_edm", uri="http://rais.nedm1:5984", username="******", password="******" ) while True: pol_curr = pol.read_curr() trans_curr = trans.read_curr() guide_curr = guide.read_curr() print "---Monitor---\nPolarizer coil current: " + pol_curr + "\nTransport coil current: " + trans_curr + "\nGuide coil current: " + guide_curr adoc['value']['pol_coil_current'] = float(pol_curr) adoc['value']['trans_coil_current'] = float(trans_curr) adoc['value']['guide_coil_current'] = float(guide_curr) des.post("_update/insert_with_timestamp",params=adoc).json() time.sleep(2) if pynedm.should_stop(): break