diff --git a/kamzik3/devices/attribute.py b/kamzik3/devices/attribute.py index b10d9d0b381e3c71a8c80f1081131f264c8ce30a..ad27a63f39eb89e3f34f9600966832d004d50d31 100755 --- a/kamzik3/devices/attribute.py +++ b/kamzik3/devices/attribute.py @@ -491,7 +491,7 @@ class Attribute(dict): else: return [attribute] - def convert_units(self, value: Optional[Quantity]): + def convert_units(self, value: Quantity): """ Convert input value to current attribute unit. @@ -507,7 +507,7 @@ class Attribute(dict): return value.to(self[UNIT]) - def within_limits(self, value: Optional[Quantity]) -> bool: + def within_limits(self, value: Quantity) -> bool: """ Check if value is within limits. @@ -519,7 +519,7 @@ class Attribute(dict): assert isinstance(value, Quantity) return bool(self.minimum() <= value <= self.maximum()) - def within_tolerance(self, value: Optional[Quantity]) -> bool: + def within_tolerance(self, value: Quantity) -> bool: """ Check if value is within tolerance. @@ -528,6 +528,8 @@ class Attribute(dict): """ assert isinstance(value, Quantity) setpoint = self.setpoint() + if setpoint is None: + setpoint = self.value() return bool( (setpoint - self.negative_tolerance()) <= value diff --git a/kamzik3/devices/deviceTango.py b/kamzik3/devices/deviceTango.py index 34bc3bfa91012df35fb4c4d29e74c731b3d9bfd6..276fc2f4a6d4dc0b09db7e700b385618b558c4da 100755 --- a/kamzik3/devices/deviceTango.py +++ b/kamzik3/devices/deviceTango.py @@ -6,7 +6,7 @@ from threading import Thread import numpy as np -from kamzik3 import DeviceError +from kamzik3 import DeviceError, units from kamzik3.constants import * from kamzik3.devices.device import Device from kamzik3.snippets.snippetsDecorators import expose_method @@ -147,6 +147,25 @@ class DeviceTango(Device, DeviceProxy): else: value = str(value) + try: + if tc.unit is None: + unit = "" # "" raises an AttributeError in pint + elif tc.unit == "%": + unit = tc.unit # "%" raises an AttributeError in pint + elif tc.unit != "" and tc.unit not in units: + self.logger.info( + f"{self.device_id}: not a valid unit '{tc.unit}', " + "default unit to ''" + ) + unit = "" + else: + unit = tc.unit + except (ValueError, TypeError): # issue with parsing in pint + self.logger.error( + f"{self.device_id}: can't parse {tc.unit}, default unit to ''" + ) + unit = "" + self.create_attribute( attribute, default_value=value, @@ -154,7 +173,7 @@ class DeviceTango(Device, DeviceProxy): description=tc.description, default_type=default_type, set_function=set_function, - unit=tc.unit, + unit=unit, min_value=min_value, max_value=max_value, decimals=decimals, @@ -475,14 +494,14 @@ class DeviceTangoEigerDetector(DeviceTango): :param Exposure: desired exposure time per frame """ - self.logger.info(f"Live view has started.") + self.logger.info("Live view has started.") self.set_attribute(["TriggerMode", VALUE], 3) if self.file_writer is not None: - self.logger.info(f"FileWriter disabled") + self.logger.info("FileWriter disabled") self.set_attribute(["FileWriter", "Mode", VALUE], 1) self.set_attribute(["FileWriter", "NimagesPerFile", VALUE], 1000000) if self.eiger_stream is not None: - self.logger.info(f"EigerStream disabled") + self.logger.info("EigerStream disabled") self.set_attribute(["EigerStream", "Mode", VALUE], 1) Exposure = float(device_units(self, "FrameTime", Exposure).m) # According to Jan 10ms is lowest frame time