Skip to content

Commit

Permalink
Merge pull request #17 from ALBA-Synchrotron/Improve-error-messages
Browse files Browse the repository at this point in the history
Improve error messages (fix #15)
  • Loading branch information
ovallcorba authored Jan 25, 2024
2 parents 64619a2 + d64f2d9 commit c66ff14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions sardana_tango/ctrl/TangoAttrCTCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ class TangoAttrCTController(ReadTangoAttributes, CounterTimerController):
+) TangoAttribute - Tango attribute to retrieve the value of the counter
+) Formula - Formula to evaluate using 'VALUE' as the tango attribute value
As examples you could have:
ch1.TangoExtraAttribute = 'my/tango/device/attribute1'
ch1.TangoAttribute = 'my/tango/device/attribute1'
ch1.Formula = '-1 * VALUE'
ch2.TangoExtraAttribute = 'my/tango/device/attribute2'
ch2.TangoAttribute = 'my/tango/device/attribute2'
ch2.Formula = 'math.sqrt(VALUE)'
ch3.TangoExtraAttribute = 'my_other/tango/device/attribute1'
ch3.TangoAttribute = 'my_other/tango/device/attribute1'
ch3.Formula = 'math.cos(VALUE)'
"""

Expand Down
24 changes: 15 additions & 9 deletions sardana_tango/ctrl/TangoAttrIORCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class TangoAttrIORController(IORegisterController):
Each IORegisters _MUST_HAVE_ extra attributes:
+) TangoAttribute - Tango attribute to retrieve the value of the IORegister
As examples you could have:
ch1.TangoExtraAttribute = 'my/tango/device/attribute1'
ch2.TangoExtraAttribute = 'my/tango/device/attribute2'
ch3.TangoExtraAttribute = 'my_other/tango/device/attribute1'
ch1.TangoAttribute = 'my/tango/device/attribute1'
ch2.TangoAttribute = 'my/tango/device/attribute2'
ch3.TangoAttribute = 'my_other/tango/device/attribute1'
Each IORegisters _MAY_HAVE_ extra attributes:
+) Labels - Human readable tag followed to the corresponding position
(integer) value.
Expand Down Expand Up @@ -211,7 +211,7 @@ def ReadOne(self, axis):
try:
positions.index(value)
except Exception:
raise Exception("Invalid position.")
raise ValueError("Invalid position.")
else:
return value
# case 1+fussy: the read from the attribute must be in one of the
Expand All @@ -222,17 +222,22 @@ def ReadOne(self, axis):
return positions[calibration.index(fussyPos)]
# if the loop ends, current value is not in the fussy areas.
self.devsExtraAttributes[axis][READFAILED] = True
raise Exception("Invalid position.")
msg = 'Value ({}) out of calibration bounds. ' \
'Please review ior calibration or write a valid value ' \
'to the underlying tango attribute: {}.{}'.format(
value, self.devsExtraAttributes[axis][DEVICE], attr)
raise ValueError(msg)
else:
raise Exception(
"Bad configuration on optional extra attributes.")
except Exception:
except Exception as e:
self._log.error('Exception reading attribute:%s.%s'
% (self.devsExtraAttributes[axis][DEVICE], attr))
try:
self.devsExtraAttributes[axis][READFAILED] = True
except Exception:
pass
raise e

def WriteOne(self, axis, value):
# If Labels is well defined, the write value must be one this struct
Expand All @@ -256,7 +261,7 @@ def WriteOne(self, axis, value):
try:
positions.index(value)
except Exception:
raise Exception("Invalid position.")
raise ValueError("Invalid position.")
dev_proxy.write_attribute(attr, value)
# case 1+fussy: the write to the to the IOR is translated to the
# central position of the calibration.
Expand All @@ -265,17 +270,18 @@ def WriteOne(self, axis, value):
try:
ior_destination = positions.index(value)
except Exception:
raise Exception("Invalid position.")
raise ValueError("Invalid position.")
self._log.debug("%s ior_destination = %s" % (
dev, ior_destination))
# central element
calibrated_position = calibration[ior_destination][1]
self._log.debug("%s calibrated_position = %s" % (
dev, calibrated_position))
dev_proxy.write_attribute(attr, calibrated_position)
except Exception:
except Exception as e:
self._log.error('Exception writing attribute:%s.%s'
% (self.devsExtraAttributes[axis][DEVICE], attr))
raise e

# ## #
# Auxiliar methods for the extra attributes
Expand Down

0 comments on commit c66ff14

Please sign in to comment.