def transition(self, state, message=""):
        """Change to a new state if the transition is allowed

        Args:
            state (str): State to transition to
            message (str): Message if the transition is to a fault state
        """
        with self.changes_squashed:
            initial_state = self.state.value
            if self.state_set.transition_allowed(initial_state=initial_state,
                                                 target_state=state):
                self.log.debug("%s: Transitioning from %s to %s", self.mri,
                               initial_state, state)
                if state == ss.DISABLED:
                    alarm = Alarm.invalid("Disabled")
                elif state == ss.FAULT:
                    alarm = Alarm.major(message)
                else:
                    alarm = Alarm()
                self.update_health(self, HealthInfo(alarm))
                self.state.set_value(state)
                self.state.set_alarm(alarm)
                for child, writeable in self._children_writeable[state].items(
                ):
                    child.meta.set_writeable(writeable)
            else:
                raise TypeError("Cannot transition from %s to %s" %
                                (initial_state, state))
    def transition(self, state, message=""):
        """Change to a new state if the transition is allowed

        Args:
            state (str): State to transition to
            message (str): Message if the transition is to a fault state
        """
        with self.changes_squashed:
            initial_state = self.state.value
            if self.stateSet.transition_allowed(
                    initial_state=initial_state, target_state=state):
                self.log.debug(
                    "Transitioning from %s to %s", initial_state, state)
                if state == ss.DISABLED:
                    alarm = Alarm.invalid("Disabled")
                elif state == ss.FAULT:
                    alarm = Alarm.major(message)
                else:
                    alarm = Alarm()
                self.update_health(self, alarm)
                self.state.set_value(state)
                self.state.set_alarm(alarm)
                for child, writeable in self._children_writeable[state].items():
                    if isinstance(child, AttributeModel):
                        child.meta.set_writeable(writeable)
                    elif isinstance(child, MethodModel):
                        child.set_writeable(writeable)
                        for element in child.takes.elements.values():
                            element.set_writeable(writeable)
            else:
                raise TypeError("Cannot transition from %s to %s" %
                                (initial_state, state))
Beispiel #3
0
 def __init__(self, mri: AMri, comms: AComms, publish: APublish = False) -> None:
     super().__init__(mri)
     self.comms = comms
     self.publish = publish
     self.client_comms: Optional[ClientComms] = None
     self.health.set_value("Uninitialized", alarm=Alarm.invalid("Uninitialized"))
     # Hooks
     self.register_hooked(ProcessStartHook, self.init)
Beispiel #4
0
 def __init__(self, process, parts, params):
     self.params = params
     super(ProxyController, self).__init__(process, params.mri, parts)
     self.client_comms = process.get_controller(params.comms)
     self.update_health(self, Alarm.invalid("Uninitialized"))
     self._response_queue = Queue()
     self._notify_response = True
     self._first_response_queue = Queue()
Beispiel #5
0
 def _update_value(self, value):
     # type: (Any) -> None
     if not value.ok or value.severity != 0:
         self.attr.set_value(None, alarm=Alarm.invalid("Bad PV value"))
     else:
         # Split "@asyn(PORT,num)" into ["PORT", "num"]
         split = value.split("(")[1].rstrip(")").split(",")
         cs_port = split[0].strip()
         cs_axis = cs_axis_names[int(split[1].strip()) - 1]
         self.attr.set_value("%s,%s" % (cs_port, cs_axis))
Beispiel #6
0
 def __init__(self, mri, comms, publish=False):
     # type: (AMri, AComms, APublish) -> None
     super(ProxyController, self).__init__(mri)
     self.comms = comms
     self.publish = publish
     self.client_comms = None
     self.health.set_value("Uninitialized",
                           alarm=Alarm.invalid("Uninitialized"))
     # Hooks
     self.register_hooked(ProcessStartHook, self.init)
Beispiel #7
0
 def _update_value(self, value, index):
     if index == 0:
         # Got CS Port
         if not value.ok:
             self.port = None
         elif value == 0:
             self.port = ""
         else:
             self.port = self.port_choices[value]
     elif index == 1:
         # Got CS Axis
         if value.ok and str(value) in CS_AXIS_NAMES + ["I"]:
             self.axis = value
         else:
             self.axis = None
     else:
         # Got PMAC Port name
         if value.ok:
             # Split "@asyn(PORT,num)" into ["PORT", "num"]
             split = value.split("(")[1].rstrip(")").split(",")
             self.pmac_attr.set_value(split[0].strip())
             self.axis_num_attr.set_value(split[1].strip())
         else:
             self.pmac_attr.set_value(None,
                                      alarm=Alarm.invalid("Bad PV value"))
             self.axis_num_attr.set_value(
                 None, alarm=Alarm.invalid("Bad PV value"))
     if self.port is None or self.axis is None:
         # Bad value or PV disconnected
         self.cs_attr.set_value(None, alarm=Alarm.invalid("Bad PV value"))
     elif self.port and self.axis:
         # Connected to a port
         self.cs_attr.set_value("%s,%s" % (self.port, self.axis))
     else:
         # Not connected to a port
         self.cs_attr.set_value("")
Beispiel #8
0
 def _update_value(self, value):
     if not value.ok:
         self.attr.set_value(None, alarm=Alarm.invalid("PV disconnected"))
     else:
         if value.severity:
             alarm = Alarm(severity=value.severity,
                           status=AlarmStatus.RECORD_STATUS,
                           message="PV in alarm state")
         else:
             alarm = Alarm.ok
         # We only have a raw_stamp attr on monitor, the initial
         # caget with CTRL doesn't give us a timestamp
         ts = TimeStamp(*getattr(value, "raw_stamp", (None, None)))
         value = self.attr.meta.validate(value)
         self.attr.set_value_alarm_ts(value, alarm, ts)
Beispiel #9
0
 def _update_value(self, value, index):
     if index == 0:
         if not value.ok:
             self.port = None
         elif value == 0:
             self.port = ""
         else:
             self.port = self.port_choices[value]
     else:
         if value.ok and str(value) in cs_axis_names + ["I"]:
             self.axis = value
         else:
             self.axis = None
     if self.port is None or self.axis is None:
         # Bad value or PV disconnected
         self.attr.set_value(None, alarm=Alarm.invalid("Bad PV value"))
     elif self.port and self.axis:
         # Connected to a port
         self.attr.set_value("%s,%s" % (self.port, self.axis))
     else:
         # Not connected to a port
         self.attr.set_value("")