def get_pv_name(self, field, handle): """Get PV name for the specified field and handle. Args: field (str): The requested field. handle (str): pytac.RB or pytac.SP. Returns: str: The readback or setpoint PV for the specified field. Raises: DataSourceException: if there is no data source for this field. FieldException: if the specified field doesn't exist. """ try: return (self._data_source_manager.get_data_source( pytac.LIVE).get_device(field).get_pv_name(handle)) except DataSourceException as e: raise DataSourceException(f"{self}: {e}") except AttributeError: raise DataSourceException( f"Cannot get PV for field {field} on element " f"{self}, as the device does not have associated PVs.") except FieldException as e: raise FieldException(f"{self}: {e}")
def __init__(self, name, cs, enabled=True, rb_pv=None, sp_pv=None): """ Args: name (str): The prefix of EPICS PV for this device. cs (ControlSystem): The control system object used to get and set the value of a PV. enabled (bool-like): Whether the device is enabled. May be a PvEnabler object. rb_pv (str): The EPICS readback PV. sp_pv (str): The EPICS setpoint PV. Raises: DataSourceException: if no PVs are provided. **Methods:** """ if rb_pv is None and sp_pv is None: raise DataSourceException( f"At least one PV ({pytac.RB} or {pytac.SP}) is " "required when creating an EpicsDevice." ) self.name = name self._cs = cs self.rb_pv = rb_pv self.sp_pv = sp_pv self._enabled = enabled
def set_value( self, field, value, units=pytac.DEFAULT, data_source=pytac.DEFAULT, throw=True, ): """Set the value for a field. This value can be set on the machine or the simulation. Args: field (str): The requested field. value (float): The value to set. units (str): pytac.ENG or pytac.PHYS. data_source (str): pytac.LIVE or pytac.SIM. throw (bool): On failure: if True, raise ControlSystemException: if False, log a warning. Raises: DataSourceException: if arguments are incorrect. FieldException: if the element does not have the specified field. """ try: self._data_source_manager.set_value(field, value, units, data_source, throw) except DataSourceException as e: raise DataSourceException(f"{self}: {e}") except FieldException as e: raise FieldException(f"{self}: {e}")
def set_value(self, value, throw=None): """Set the value on the device. Args: value (numeric): the value to set. throw (bool): Irrelevant in this case as a control system is not used, only supported to conform with the base class. """ if self._readonly: raise DataSourceException("Cannot change value of readonly SimpleDevice") self.value = value
def get_data_source(self, data_source_type): """Get a data source. Args: data_source_type (str): the type of the data source being set pytac.LIVE or pytac.SIM. Raises: DataSourceException: if there is no data source on the given field. """ try: return self._data_sources[data_source_type] except KeyError: raise DataSourceException( f"No data source {data_source_type} on manager {self}.")
def get_device(self, field): """Get the device for the given field. A DeviceDataSource must be set before calling this method, this defaults to pytac.LIVE as that is the only data source that currently uses devices. Args: field (str): The lookup key to find the device on an element. Returns: Device: The device on the given field. Raises: DataSourceException: if no DeviceDataSource is set. """ try: return self._data_source_manager.get_device(field) except DataSourceException as e: raise DataSourceException(f"{self}: {e}.")
def add_device(self, field, device, uc): """Add device and unit conversion objects to a given field. A DeviceDataSource must be set before calling this method, this defaults to pytac.LIVE as that is the only data source that currently uses devices. Args: field (str): The key to store the unit conversion and device objects. device (Device): The device object used for this field. uc (UnitConv): The unit conversion object used for this field. Raises: DataSourceException: if no DeviceDataSource is set. """ try: self._data_source_manager.add_device(field, device, uc) except DataSourceException as e: raise DataSourceException(f"{self}: {e}.")
def get_pv_name(self, field, handle): """Get the PV name for a specific field, and handle on this lattice. Args: field (str): The requested field. handle (str): pytac.RB or pytac.SP. Returns: str: The readback or setpoint PV for the specified field. """ try: return ( self._data_source_manager.get_data_source(pytac.LIVE) .get_device(field) .get_pv_name(handle) ) except AttributeError: raise DataSourceException( f"Cannot get PV for field {field} on lattice " f"{self}, as the device does not have associated PVs." )
def set_default_data_source(self, data_source_type: str) -> None: """Sets the default data source for the lattice and all its elements. Args: data_source_type: The default data source to be set across the entire lattice, pytac.LIVE or pytac.SIM. Raises: DataSourceException: if specified default data source is not a valid data source. """ if (data_source_type == pytac.LIVE) or (data_source_type == pytac.SIM): self._data_source_manager.default_data_source = data_source_type elems = self.get_elements() for elem in elems: elem._data_source_manager.default_data_source = data_source_type else: raise DataSourceException( f"{data_source_type} is not a data source. " f"Please enter {pytac.LIVE} or {pytac.SIM}." )
def get_value( self, field, handle=pytac.RB, units=pytac.DEFAULT, data_source=pytac.DEFAULT, throw=True, ): """Get the value for a field. Returns the value of a field on the element. This value is uniquely identified by a field and a handle. The returned value is either in engineering or physics units. The data_source flag returns either real or simulated values. Args: field (str): The requested field. handle (str): pytac.SP or pytac.RB. units (str): pytac.ENG or pytac.PHYS returned. data_source (str): pytac.LIVE or pytac.SIM. throw (bool): On failure: if True, raise ControlSystemException; if False, return None and log a warning. Returns: float: The value of the requested field Raises: DataSourceException: if there is no data source on the given field. FieldException: if the element does not have the specified field. """ try: return self._data_source_manager.get_value(field, handle, units, data_source, throw) except DataSourceException as e: raise DataSourceException(f"{self}: {e}") except FieldException as e: raise FieldException(f"{self}: {e}")