def PV(self, attr, connect=True, **kw): """return epics.PV for a device attribute""" if attr in self._aliases: attr = self._aliases[attr] if attr not in self._pvs and attr not in no_attrs: pvname = attr if self._prefix is not None: pvname = "%s%s" % (self._prefix, attr) self._pvs[attr] = get_pv(pvname, **kw) if connect and not self._pvs[attr].connected: self._pvs[attr].wait_for_connection() return self._pvs[attr]
def restore_pvs(filepath, debug=False): """ Restore pvs from a save file via Channel Access debug - Set to True if you want a line printed for each value set Returns True if all pvs were restored successfully. """ pv_vals = [] failures = [] # preload PV names and values, hoping PV connections happen in background with open(filepath, 'r') as fh: for line in fh.readlines(): if len(line) < 2 or line.startswith('<END') or line.startswith( '#'): continue pvname, value = [w.strip() for w in line[:-1].split(' ', 1)] if value.startswith('@array@'): value = value.replace('@array@', '').strip() if value.startswith('{') and value.endswith('}'): value = value[1:-1] value = json.loads(value) thispv = get_pv(pvname, connect=False) pv_vals.append((thispv, value)) for thispv, value in pv_vals: thispv.connect() pvname = thispv.pvname if not thispv.connected: print("Cannot connect to %s" % (pvname)) elif not thispv.write_access: print("No write access to %s" % (pvname)) else: if debug: print("Setting %s to %s" % (pvname, value)) try: thispv.put(value, wait=False) except: exctype, excvalue, exctrace = sys.exc_info() print("Error restoring %s to %s : %s" % (pvname, value, exctype, excvalue)) failues.append(pvname) return len(failures) == 0
def add_pv(self, pvname, attr=None, **kw): """add a PV with an optional attribute name that may not exactly correspond to the mapping of Attribute -> Prefix + Delim + Attribute That is, with a device defined as >>> dev = Device('XXX', delim='.') getting the VAL attribute >>> dev.get('VAL') # or dev.VAL becomes 'caget(XXX.VAL)'. With add_pv(), one can add a non-conforming PV to the collection: >>> dev.add_pv('XXX_status.VAL', attr='status') and then use as >>> dev.get('status') # or dev.status If attr is not specified, the full pvname will be used. """ if attr is None: attr = pvname self._pvs[attr] = get_pv(pvname, **kw) return self._pvs[attr]
def read_request_file(self, request_file=None): if request_file is not None: self.request_file = request_file self.pvs = [] for pvname in _parse_request_file(request_file): self.pvs.append(get_pv(pvname, connect=False))