# IPython import IPython.utils.traitlets as traitlets # ECLI from ecli_core import AliasedPV from ecli_plugin import ECLIPlugin import ecli_util as util from ecli_util.epics_device import (get_record_from_device, get_records_from_devices, ) from ecli_util.decorators import ECLIExport from ecli_util.magic_args import (ecli_magic_args, argument) import epics logger = logging.getLogger('ECLI.Motor') motor_field_info = util.get_record_fields('motor') # Loading of this extension def load_ipython_extension(ipython): return util.generic_load_ext(ipython, ECLIMotor, logger=logger, globals_=globals()) def unload_ipython_extension(ipython): return util.generic_unload_ext(ipython, ECLIMotor) DEFAULT_MOTOR_INFO = { 'User': { 'High': '.HLM', 'Current': '.RBV',
def fields(self, pv, string, max_interest=4, values=True): ''' Search the field information database for 'text'. If the first argument is a PV it will detect its record type, otherwise use a record type (.RTYP) to start with. ''' try: rf = util.get_record_fields(pv) except IOError: # not a record type, or not one we have information on # try it as a PV instead: rtype = util.get_record_type(pv) rf = util.get_record_fields(rtype) else: rtype = pv if isinstance(string, (list, tuple)): text = ' '.join(string) else: text = string headers = ['Field'] + [col.capitalize() for col in rf.columns] table = SimpleTable(headers) rows = list([name] + info for name, info in rf.find(text)) for row in rows: table.add_row(row) remove_rows = [] if rtype != pv and values: # this means a PV was passed in and the RTYP was determined table.add_column('Value', index=1, fill='') for i, row in enumerate(table.rows): if i == 0: continue field = row[0] try: interest = int(table['Interest', i]) except: interest = 0 else: if interest > max_interest: remove_rows.append(i) continue if interest > 3: timeout = self.fields_timeout / 2 else: timeout = self.fields_timeout value = epics.caget('%s.%s' % (pv, field), connection_timeout=timeout, verbose=True) if value is None: value = '' table[1, i] = '%s' % value removed = 0 for row in remove_rows: table.remove_row(row - removed) removed += 1 return rtype, table