frappy_psi.sea: use ReadFailedError

change error class on reading parameters in SEA from HardwareError
to ReadFailed. This is in most cases more appropriate.

TODO: find errors in SEA that should be should be HardwareErrors
and a mechanism to indicate this

+ for errors related to disabled modules use the DISABLED status

Change-Id: I0342a34185a66dcf874c6ca034b7cefc98bf9c8a
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/34022
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
zolliker 2024-06-24 13:30:49 +02:00
parent 15fc9ca16c
commit 09f4f1d192

View File

@ -38,9 +38,9 @@ from os.path import expanduser, join, exists
from frappy.client import ProxyClient from frappy.client import ProxyClient
from frappy.datatypes import ArrayOf, BoolType, \ from frappy.datatypes import ArrayOf, BoolType, \
EnumType, FloatRange, IntRange, StringType EnumType, FloatRange, IntRange, StringType, StatusType
from frappy.core import IDLE, BUSY, ERROR from frappy.core import IDLE, BUSY, ERROR, DISABLED
from frappy.errors import ConfigError, HardwareError, CommunicationFailedError from frappy.errors import ConfigError, HardwareError, ReadFailedError, CommunicationFailedError
from frappy.lib import generalConfig, mkthread from frappy.lib import generalConfig, mkthread
from frappy.lib.asynconn import AsynConn, ConnectionClosed from frappy.lib.asynconn import AsynConn, ConnectionClosed
from frappy.modulebase import Done from frappy.modulebase import Done
@ -307,7 +307,8 @@ class SeaClient(ProxyClient, Module):
readerror = None readerror = None
if path.endswith('.geterror'): if path.endswith('.geterror'):
if value: if value:
readerror = HardwareError(value) # TODO: add mechanism in SEA to indicate hardware errors
readerror = ReadFailedError(value)
path = path.rsplit('.', 1)[0] path = path.rsplit('.', 1)[0]
value = None value = None
mplist = self.path2param.get(path) mplist = self.path2param.get(path)
@ -422,9 +423,9 @@ class SeaEnum(EnumType):
def __call__(self, value): def __call__(self, value):
try: try:
value = int(value) value = int(value)
except TypeError: return super().__call__(value)
pass except Exception as e:
return super().__call__(value) raise ReadFailedError(e)
def get_datatype(paramdesc): def get_datatype(paramdesc):
@ -658,6 +659,8 @@ class SeaReadable(SeaModule, Readable):
_readerror = None _readerror = None
_status = IDLE, '' _status = IDLE, ''
status = Parameter(datatype=StatusType(Readable, 'DISABLED'))
def update_value(self, value, timestamp, readerror): def update_value(self, value, timestamp, readerror):
# make sure status is always ERROR when reading value fails # make sure status is always ERROR when reading value fails
self._readerror = readerror self._readerror = readerror
@ -669,9 +672,9 @@ class SeaReadable(SeaModule, Readable):
self.read_status() # send event for ordinary self._status self.read_status() # send event for ordinary self._status
def update_status(self, value, timestamp, readerror): def update_status(self, value, timestamp, readerror):
if readerror: if 'disable' in value.lower():
value = f'{readerror.name} - {readerror}' self._status = DISABLED, value
if value == '': elif value == '':
self._status = IDLE, '' self._status = IDLE, ''
else: else:
self._status = ERROR, value self._status = ERROR, value
@ -679,6 +682,8 @@ class SeaReadable(SeaModule, Readable):
def read_status(self): def read_status(self):
if self._readerror: if self._readerror:
if 'disable' in str(self._readerror).lower():
return DISABLED, str(self._readerror)
return ERROR, f'{self._readerror.name} - {self._readerror}' return ERROR, f'{self._readerror.name} - {self._readerror}'
return self._status return self._status
@ -696,6 +701,8 @@ class SeaWritable(SeaReadable, Writable):
class SeaDrivable(SeaReadable, Drivable): class SeaDrivable(SeaReadable, Drivable):
_is_running = 0 _is_running = 0
status = Parameter(datatype=StatusType(Drivable, 'DISABLED'))
def earlyInit(self): def earlyInit(self):
super().earlyInit() super().earlyInit()
self._run_event = threading.Event() self._run_event = threading.Event()