diff --git a/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py b/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py index 718ea431d6d24962ad7f437e3941e7609f89927f..4dd07132621f660b825b57c2ff0683fa3b6b85d4 100644 --- a/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py +++ b/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py @@ -1,8 +1,8 @@ from tango.server import attribute -from tango import AttrWriteType +from tango import AttrWriteType, DevState import numpy -from tangostationcontrol.devices.device_decorators import only_when_on, fault_on_error +from tangostationcontrol.devices.device_decorators import only_in_states, fault_on_error import logging logger = logging.getLogger() @@ -72,7 +72,7 @@ class attribute_wrapper(attribute): if access == AttrWriteType.READ_WRITE: """ if the attribute is of READ_WRITE type, assign the RW and write function to it""" - @only_when_on() + @only_in_states([DevState.STANDBY, DevState.ON], log=False) @fault_on_error() def read_RW(device): # print("read_RW {}, {}x{}, {}, {}".format(me.name, me.dim_x, me.dim_y, me.attr_type, me.value)) @@ -85,7 +85,7 @@ class attribute_wrapper(attribute): raise Exception("Attribute read_RW function error, attempted to read value_dict with key: `%s`, are you sure this exists?", self) from e - @only_when_on() + @only_in_states([DevState.STANDBY, DevState.ON], log=False) @fault_on_error() def write_RW(device, value): """ @@ -102,7 +102,7 @@ class attribute_wrapper(attribute): else: """ if the attribute is of READ type, assign the read function to it""" - @only_when_on() + @only_in_states([DevState.STANDBY, DevState.ON], log=False) @fault_on_error() def read_R(device): """ diff --git a/tangostationcontrol/tangostationcontrol/devices/apsct.py b/tangostationcontrol/tangostationcontrol/devices/apsct.py index add4e146cdb5fb4282a49f9394c552465b088a26..90a8be0d51f399d8135ddb486bd860a5d047abeb 100644 --- a/tangostationcontrol/tangostationcontrol/devices/apsct.py +++ b/tangostationcontrol/tangostationcontrol/devices/apsct.py @@ -73,19 +73,14 @@ class APSCT(opcua_device): def _initialise_hardware(self): """ Initialise the APSCT hardware. """ - # method calls don't work yet, so don't use them to allow the boot - # device to initialise us without errors - logger.error("OPC-UA methods not supported yet, not initialising APSCT hardware!") - return - # Cycle clock self.CLK_off() self.wait_attribute("APSCTTR_translator_busy_R", False, 10) self.CLK_on() self.wait_attribute("APSCTTR_translator_busy_R", False, 10) - if not self.APSCT_PLL_200MHz_locked_R: - if self.APSCT_I2C_error_R: + if not self.proxy.APSCT_PLL_200MHz_locked_R: + if self.proxy.APSCT_I2C_error_R: raise Exception("I2C is not working. Maybe power cycle subrack to restart CLK board and translator?") else: raise Exception("200MHz signal is not locked. The subrack probably do not receive clock input or the CLK PCB is broken?") diff --git a/tangostationcontrol/tangostationcontrol/devices/device_decorators.py b/tangostationcontrol/tangostationcontrol/devices/device_decorators.py index b3f203bfff1fec77efbc0b2d95d8c464a97dcb71..bb04cdbca5026c9485026856faf80b59fcae4c18 100644 --- a/tangostationcontrol/tangostationcontrol/devices/device_decorators.py +++ b/tangostationcontrol/tangostationcontrol/devices/device_decorators.py @@ -7,7 +7,7 @@ logger = logging.getLogger() __all__ = ["only_in_states", "only_when_on", "fault_on_error"] -def only_in_states(allowed_states): +def only_in_states(allowed_states, log=True): """ Wrapper to call and return the wrapped function if the device is in one of the given states. Otherwise a PyTango exception is thrown. @@ -18,7 +18,9 @@ def only_in_states(allowed_states): if self.get_state() in allowed_states: return func(self, *args, **kwargs) - logger.warning("Illegal command: Function %s can only be called in states %s. Current state: %s" % (func.__name__, allowed_states, self.get_state())) + if log: + logger.warning("Illegal command: Function %s can only be called in states %s. Current state: %s" % (func.__name__, allowed_states, self.get_state())) + Except.throw_exception("IllegalCommand", "Function can only be called in states %s. Current state: %s" % (allowed_states, self.get_state()), func.__name__) return state_check_wrapper diff --git a/tangostationcontrol/tangostationcontrol/devices/opcua_device.py b/tangostationcontrol/tangostationcontrol/devices/opcua_device.py index 9f846533533e5211cbb7a5aa5018b87364f08463..d3668cfae31a23758573db82d29b5cb9ed38d1ba 100644 --- a/tangostationcontrol/tangostationcontrol/devices/opcua_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/opcua_device.py @@ -119,7 +119,7 @@ class opcua_device(lofar_device): i.set_pass_func() self.opcua_missing_attributes.append(",".join(self.opcua_connection.get_node_path(i.comms_annotation))) - logger.warning("error while setting the attribute {} read/write function. {}".format(i, e)) + logger.warning(f"Error while setting the attribute {i.comms_annotation} read/write function.", exc_info=True) @log_exceptions() def configure_for_off(self): diff --git a/tangostationcontrol/tangostationcontrol/devices/recv.py b/tangostationcontrol/tangostationcontrol/devices/recv.py index 4ac93d85abcf66d4c8dc25ab60a1fae89fbef794..c713690b7b810837eb474b0f5fc133457b547640 100644 --- a/tangostationcontrol/tangostationcontrol/devices/recv.py +++ b/tangostationcontrol/tangostationcontrol/devices/recv.py @@ -151,11 +151,6 @@ class RECV(opcua_device): def _initialise_hardware(self): """ Initialise the RCU hardware. """ - # method calls don't work yet, so don't use them to allow the boot - # device to initialise us without errors - logger.error("OPC-UA methods not supported yet, not initialising RCU hardware!") - return - # Cycle RCUs self.RCU_off() self.wait_attribute("RECVTR_translator_busy_R", False, 5)