Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages (fix #15) #17

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 18 additions & 12 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 @@ -169,9 +169,9 @@ def StateOne(self, axis):
"Not yet configured the Tango Attribute, "
"or cannot proxy it")
if not lcalibration == 0 and not llabels == lcalibration:
return(State.Disable,
"Bad configuration of the extra attributes, "
"this cannot be operated")
return (State.Disable,
"Bad configuration of the extra attributes, "
"this cannot be operated")
else:
dev_state = dev_proxy.state()
if readFailed and not dev_state == DevState.MOVING:
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
Loading