diff --git a/frappy/client/interactive.py b/frappy/client/interactive.py index a60d9a5..7f5d4c0 100644 --- a/frappy/client/interactive.py +++ b/frappy/client/interactive.py @@ -45,7 +45,7 @@ import re from queue import Queue from frappy.client import SecopClient from frappy.errors import SECoPError -from frappy.datatypes import get_datatype +from frappy.datatypes import get_datatype, StatusType main = sys.modules['__main__'] @@ -130,7 +130,7 @@ class Module: return '%s.%s = %s' % (self._name, pname, r) def _isBusy(self): - return 300 <= self.status[0] < 400 + return self.status[0] // 100 == StatusType.BUSY // 100 def _status_value_update(self, m, p, status, t, e): if self._running: diff --git a/frappy/core.py b/frappy/core.py index 6c3ffdc..3af1835 100644 --- a/frappy/core.py +++ b/frappy/core.py @@ -27,7 +27,7 @@ # pylint: disable=unused-import from frappy.datatypes import ArrayOf, BLOBType, BoolType, EnumType, \ - FloatRange, IntRange, ScaledInteger, StringType, StructOf, TupleOf + FloatRange, IntRange, ScaledInteger, StringType, StructOf, TupleOf, StatusType from frappy.lib.enum import Enum from frappy.modules import Attached, Communicator, \ Done, Drivable, Feature, Module, Readable, Writable, HasAccessibles @@ -39,7 +39,22 @@ from frappy.persistent import PersistentMixin, PersistentParam from frappy.rwhandler import ReadHandler, WriteHandler, CommonReadHandler, \ CommonWriteHandler, nopoll -ERROR = Drivable.Status.ERROR -WARN = Drivable.Status.WARN -BUSY = Drivable.Status.BUSY -IDLE = Drivable.Status.IDLE +DISABLED = StatusType.DISABLED +IDLE = StatusType.IDLE +STANDBY = StatusType.STANDBY +PREPARED = StatusType.PREPARED +WARN = StatusType.WARN +WARN_STANDBY = StatusType.WARN_STANDBY +WARN_PREPARED = StatusType.WARN_PREPARED +UNSTABLE = StatusType.UNSTABLE # no SECoP standard (yet) +BUSY = StatusType.BUSY +DISABLING = StatusType.DISABLING +INITIALIZING = StatusType.INITIALIZING +PREPARING = StatusType.PREPARING +STARTING = StatusType.STARTING +RAMPING = StatusType.RAMPING +STABILIZING = StatusType.STABILIZING +FINALIZING = StatusType.FINALIZING +ERROR = StatusType.ERROR +ERROR_STANDBY = StatusType.ERROR_STANDBY +ERROR_PREPARED = StatusType.ERROR_PREPARED diff --git a/frappy/datatypes.py b/frappy/datatypes.py index 00b2ebd..438d8e8 100644 --- a/frappy/datatypes.py +++ b/frappy/datatypes.py @@ -1243,6 +1243,26 @@ class LimitsType(TupleOf): class StatusType(TupleOf): # shorten initialisation and allow access to status enumMembers from status values + DISABLED = 0 + IDLE = 100 + STANDBY = 130 + PREPARED = 150 + WARN = 200 + WARN_STANDBY = 230 + WARN_PREPARED = 250 + UNSTABLE = 270 # no SECoP standard (yet) + BUSY = 300 + DISABLING = 310 + INITIALIZING = 320 + PREPARING = 340 + STARTING = 360 + RAMPING = 370 + STABILIZING = 380 + FINALIZING = 390 + ERROR = 400 + ERROR_STANDBY = 430 + ERROR_PREPARED = 450 + def __init__(self, enum): super().__init__(EnumType(enum), StringType()) self._enum = enum diff --git a/frappy/gui/moduleoverview.py b/frappy/gui/moduleoverview.py index 2649bde..9a490f9 100644 --- a/frappy/gui/moduleoverview.py +++ b/frappy/gui/moduleoverview.py @@ -1,3 +1,4 @@ +from frappy.datatypes import StatusType from frappy.gui.qt import QIcon, Qt, QTreeWidget, QTreeWidgetItem, pyqtSignal @@ -70,7 +71,7 @@ class ModuleItem(QTreeWidgetItem): return if parameter == 'status': if value.readerror: - self.setIcon(self.display[parameter], ModuleItem.statusIcon(400)) # 400=ERROR + self.setIcon(self.display[parameter], ModuleItem.statusIcon(StatusType.ERROR)) self.setText(self.display['status/text'], str(value.readerror)) else: self.setIcon(self.display[parameter], ModuleItem.statusIcon(value.value[0].value)) diff --git a/frappy/modules.py b/frappy/modules.py index 20ca29a..3566bce 100644 --- a/frappy/modules.py +++ b/frappy/modules.py @@ -764,16 +764,16 @@ class Readable(Module): """basic readable module""" # pylint: disable=invalid-name Status = Enum('Status', - IDLE=100, - WARN=200, - UNSTABLE=270, - ERROR=400, - DISABLED=0, - UNKNOWN=401, + IDLE=StatusType.IDLE, + WARN=StatusType.WARN, + UNSTABLE=270, # not SECoP standard. TODO: remove and adapt entangle + ERROR=StatusType.ERROR, + DISABLED=StatusType.DISABLED, + UNKNOWN=401, # not SECoP standard. TODO: remove and adapt entangle and epics ) #: status codes value = Parameter('current value of the module', FloatRange()) - status = Parameter('current status of the module', TupleOf(EnumType(Status), StringType()), + status = Parameter('current status of the module', StatusType(Status), default=(Status.IDLE, '')) pollinterval = Parameter('default poll interval', FloatRange(0.1, 120), default=5, readonly=False, export=True) @@ -805,7 +805,7 @@ class Writable(Readable): class Drivable(Writable): """basic drivable module""" - Status = Enum(Readable.Status, BUSY=300) #: status codes + Status = Enum(Readable.Status, BUSY=StatusType.BUSY) #: status codes status = Parameter(datatype=StatusType(Status)) # override Readable.status @@ -814,14 +814,14 @@ class Drivable(Writable): returns True when busy (also when finalizing) """ - return 300 <= (status or self.status)[0] < 400 + return StatusType.BUSY <= (status or self.status)[0] < StatusType.ERROR def isDriving(self, status=None): """check for driving, treating status substates correctly returns True when busy, but not finalizing """ - return 300 <= (status or self.status)[0] < 390 + return StatusType.BUSY <= (status or self.status)[0] < StatusType.FINALIZING @Command(None, result=None) def stop(self):