diff --git a/utils/epics.py b/utils/epics.py index f89c220..2544613 100644 --- a/utils/epics.py +++ b/utils/epics.py @@ -12,6 +12,7 @@ class DataGetter: self.timeout = timeout self.quiet = quiet + def __call__(self, pv): connected = pv.wait_for_connection(self.timeout) @@ -41,7 +42,47 @@ class DataGetter: if not self.quiet: msg = colored(col, msg) print(pv.pvname, msg) + return data +class DataPutter: + + def __init__(self, timeout, quiet): + self.timeout = timeout + self.quiet = quiet + + + def __call__(self, pv, value): + connected = pv.wait_for_connection(self.timeout) + + if not connected: + status = False + msg = MSG_NOT_CONNECTED + col = COL_NOT_CONNECTED + else: + status = pv_put_waiting(pv, value, self.timeout) #TODO: use same timeout twice? + msg = f"put {value} " + if status: + msg += "successful" + col = COL_SUCCESS + else: + msg += "timed out" + col = COL_ALARM + + if not self.quiet: + msg = colored(col, msg) + print(pv.pvname, msg) + + return status + + + +def pv_put_waiting(pv, value, timeout): + """wraps waiting PV.put and returns completion status""" + pv.put(value, wait=True, timeout=timeout, use_complete=True) + return pv.put_complete + + +