diff --git a/devices/PCC.py b/devices/PCC.py index 472ab404b68b8d78e8fe3659bbc3ec7334480cc4..fdb30ed39db4df9f18a21bfd2089e345127090c9 100644 --- a/devices/PCC.py +++ b/devices/PCC.py @@ -15,8 +15,8 @@ from tango import DebugIt from tango.server import run, command from tango.server import device_property -# Additional import +# Additional import from clients.opcua_connection import OPCUAConnection from src.attribute_wrapper import * from src.hardware_device import * @@ -27,23 +27,9 @@ __all__ = ["PCC", "main"] @device_logging_to_python({"device": "PCC"}) class PCC(hardware_device): - """ - - **Properties:** - - - Device Property - OPC_Server_Name - - Type:'DevString' - OPC_Server_Port - - Type:'DevULong' - OPC_Time_Out - - Type:'DevDouble' - """ - # ----------------- # Device Properties # ----------------- - OPC_Server_Name = device_property( dtype='DevString', mandatory=True @@ -58,7 +44,8 @@ class PCC(hardware_device): dtype='DevDouble', mandatory=True ) - OPC_namespace = device_property( + + OPC_Namespace = device_property( dtype='DevString', mandatory=False ) @@ -66,32 +53,57 @@ class PCC(hardware_device): # ---------- # Attributes # ---------- + RCU_state_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_state_R"], datatype=numpy.str_, access=AttrWriteType.READ_WRITE) + RCU_mask_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_mask_RW"], datatype=numpy.bool_, dims=(32,), access=AttrWriteType.READ_WRITE) + Ant_mask_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:Ant_mask_RW"], datatype=numpy.bool_, dims=(3, 32), access=AttrWriteType.READ_WRITE) + RCU_attenuator_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_attenuator_R"], datatype=numpy.int64, dims=(3, 32)) + RCU_attenuator_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_attenuator_RW"], datatype=numpy.int64, dims=(3, 32), access=AttrWriteType.READ_WRITE) + RCU_band_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_band_R"], datatype=numpy.int64, dims=(3, 32)) + RCU_band_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_band_RW"], datatype=numpy.int64, dims=(3, 32), access=AttrWriteType.READ_WRITE) + RCU_temperature_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_temperature_R"], datatype=numpy.float64, dims=(32,)) + RCU_Pwr_dig_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_Pwr_dig_R"], datatype=numpy.int64, dims=(32,)) + RCU_LED0_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_LED0_R"], datatype=numpy.int64, dims=(32,)) + RCU_LED0_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_LED0_RW"], datatype=numpy.int64, dims=(32,), access=AttrWriteType.READ_WRITE) + RCU_ADC_lock_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_ADC_lock_R"], datatype=numpy.int64, dims=(3, 32)) + RCU_ADC_SYNC_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_ADC_SYNC_R"], datatype=numpy.int64, dims=(3, 32)) + RCU_ADC_JESD_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_ADC_JESD_R"], datatype=numpy.int64, dims=(3, 32)) + RCU_ADC_CML_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_ADC_CML_R"], datatype=numpy.int64, dims=(3, 32)) + RCU_OUT1_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_OUT1_R"], datatype=numpy.int64, dims=(3, 32)) + RCU_OUT2_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_OUT2_R"], datatype=numpy.int64, dims=(3, 32)) + RCU_ID_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_ID_R"], datatype=numpy.int64, dims=(32,)) + RCU_version_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_version_R"], datatype=numpy.str_, dims=(32,)) - HBA_element_beamformer_delays_R = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_beamformer_delays_R"], datatype=numpy.int64, dims=(32,96)) - HBA_element_beamformer_delays_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_beamformer_delays_RW"], datatype=numpy.int64, dims=(32,96), access=AttrWriteType.READ_WRITE) - HBA_element_pwr_R = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_pwr_R"], datatype=numpy.int64, dims=(32,96)) - HBA_element_pwr_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_pwr_RW"], datatype=numpy.int64, dims=(32,96), access=AttrWriteType.READ_WRITE) + HBA_element_beamformer_delays_R = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_beamformer_delays_R"], datatype=numpy.int64, dims=(32, 96)) + + HBA_element_beamformer_delays_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_beamformer_delays_RW"], datatype=numpy.int64, dims=(32, 96), access=AttrWriteType.READ_WRITE) + + HBA_element_pwr_R = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_pwr_R"], datatype=numpy.int64, dims=(32, 96)) + + HBA_element_pwr_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_pwr_RW"], datatype=numpy.int64, dims=(32, 96), access=AttrWriteType.READ_WRITE) + + uC_ID_R = attribute_wrapper(comms_annotation=["2:PCC", "2:uC_ID_R"], datatype=numpy.int64, dims=(32,)) RCU_monitor_rate_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_monitor_rate_RW"], datatype=numpy.float64, access=AttrWriteType.READ_WRITE) + def delete_device(self): """Hook to delete resources allocated in init_device. @@ -100,7 +112,6 @@ class PCC(hardware_device): destructor and by the device Init command (a Tango built-in). """ self.debug_stream("Shutting down...") - self.Off() self.debug_stream("Shut down. Good bye.") @@ -111,24 +122,17 @@ class PCC(hardware_device): """ user code here. is called when the state is set to OFF """ # Stop keep-alive - self.opcua_connection.stop() + self.OPCua_client.disconnect() def initialise(self): """ user code here. is called when the state is set to INIT """ - # Init the dict that contains function to OPC-UA function mappings. - self.function_mapping = {} - self.function_mapping["RCU_on"] = {} - self.function_mapping["RCU_off"] = {} - self.function_mapping["ADC_on"] = {} - self.function_mapping["RCU_update"] = {} - self.function_mapping["CLK_on"] = {} - self.function_mapping["CLK_off"] = {} - self.function_mapping["CLK_PLL_setup"] = {} - #set up the OPC ua client - self.OPCua_client = OPCUAConnection("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), "http://lofar.eu", self.OPC_Time_Out, self.Standby, self.Fault, self) + namespace = "http://lofar.eu" + if self.OPC_Namespace is not None: + namespace = self.OPC_Namespace + self.OPCua_client = OPCUAConnection("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), namespace, self.OPC_Time_Out, self.Standby, self.Fault, self) # map the attributes to the OPC ua comm client for i in self.attr_list(): @@ -137,6 +141,16 @@ class PCC(hardware_device): except: pass + # Init the dict that contains function to OPC-UA function mappings. + self.function_mapping = {} + self.function_mapping["RCU_off"] = self.OPCua_client._setup_annotation(["2:PCC", "2:RCU_off"]) + self.function_mapping["RCU_on"] = self.OPCua_client._setup_annotation(["2:PCC", "2:RCU_on"]) + self.function_mapping["ADC_on"] = self.OPCua_client._setup_annotation(["2:PCC", "2:ADC_on"]) + self.function_mapping["RCU_update"] = self.OPCua_client._setup_annotation(["2:PCC", "2:RCU_update"]) + self.function_mapping["CLK_off"] = self.OPCua_client._setup_annotation(["2:PCC", "2:CLK_off"]) + self.function_mapping["CLK_on"] = self.OPCua_client._setup_annotation(["2:PCC", "2:CLK_on"]) + self.function_mapping["CLK_PLL_setup"] = self.OPCua_client._setup_annotation(["2:PCC", "2:CLK_PLL_setup"]) + self.OPCua_client.start() # -------- diff --git a/devices/clients/opcua_connection.py b/devices/clients/opcua_connection.py index 8c6de0fcd89b8341bdddbf3019ad0a7531db1b19..9e5e488905775d0b8941e5c508d7179b5b9d73bd 100644 --- a/devices/clients/opcua_connection.py +++ b/devices/clients/opcua_connection.py @@ -1,5 +1,5 @@ from src.comms_client import * - +import opcua __all__ = ["OPCUAConnection"] @@ -39,7 +39,7 @@ class OPCUAConnection(CommClient): """ super().__init__(on_func, fault_func, streams, try_interval) - self.client = Client(address, timeout) + self.client = opcua.Client(address, timeout) # Explicitly connect if not self.connect(): @@ -89,16 +89,19 @@ class OPCUAConnection(CommClient): try: self.client.disconnect() except Exception as e: - self.streams.error_stream("Disconnect from OPC-UA server %s failed: %s", self._servername(), e) + self.streams.error_stream("Disconnect from OPC-UA server {} failed: {}".format(self._servername(), e)) def ping(self): """ ping the client to make sure the connection with the client is still functional. """ try: - self.client.send_hello() + if self.connected is True: + self.client.send_hello() + else: + self.streams.debug_stream("Will not ping OPC-UA server {} because the connection is inactive.".format(self._servername())) except Exception as e: - raise Exception("Lost connection to server %s: %s", self._servername(), e) + raise Exception("Lost connection to server {}.".format(self._servername())) from e def _setup_annotation(self, annotation): """ @@ -114,13 +117,12 @@ class OPCUAConnection(CommClient): elif isinstance(annotation, list): path = annotation else: - raise Exception("OPC-ua mapping requires either a list of the path or dict with the path. Was given %s type containing: %s", type(annotation), annotation) + raise Exception("OPC-ua mapping requires either a list of the path or dict with the path. Was given {} type containing: {}".format(type(annotation), annotation)) try: node = self.obj.get_child(path) except Exception as e: - self.streams.error_stream("Could not get node: %s on server %s: %s", path, self._servername(), e) - raise Exception("Could not get node: %s on server %s", path, self._servername()) from e + raise Exception("Could not get node: {} on server {}".format(path, self._servername())) from e return node diff --git a/devices/src/comms_client.py b/devices/src/comms_client.py index 672ec4c399f22890cf40779edb35291e4cb0da89..0cf7fb9801a91b8289fef480456e932bf2581626 100644 --- a/devices/src/comms_client.py +++ b/devices/src/comms_client.py @@ -3,9 +3,6 @@ import socket import time import numpy -import opcua -from opcua import Client - from tango import DevState diff --git a/devices/src/hardware_device.py b/devices/src/hardware_device.py index 01bc2f445e8bb29ecd0ad38198c84d05cc5df1e0..36f89cdfe2fed2dae107722c589bc34fb82328e4 100644 --- a/devices/src/hardware_device.py +++ b/devices/src/hardware_device.py @@ -84,9 +84,9 @@ class hardware_device(Device): """ self.set_state(DevState.INIT) self.setup_value_dict() - - self.initialise() + self.standby() + self.set_state(DevState.STANDBY) @only_in_states([DevState.INIT]) def Standby(self):