Skip to content
Snippets Groups Projects
Commit 58347c0a authored by Jan David Mol's avatar Jan David Mol
Browse files

Merge branch...

Merge branch '2021-04-02T17.33.12-branched_from_master-Adjustments_for_attribute_wrapper' into 'master'

Adjustments and fixes for attribute_wrapper merge

See merge request !12
parents 018676f3 cbeaacef
No related branches found
No related tags found
1 merge request!12Adjustments and fixes for attribute_wrapper merge
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
from tango import DebugIt from tango import DebugIt
from tango.server import run, command from tango.server import run, command
from tango.server import device_property from tango.server import device_property
# Additional import
# Additional import
from clients.opcua_connection import OPCUAConnection from clients.opcua_connection import OPCUAConnection
from src.attribute_wrapper import * from src.attribute_wrapper import *
from src.hardware_device import * from src.hardware_device import *
...@@ -27,23 +27,9 @@ __all__ = ["PCC", "main"] ...@@ -27,23 +27,9 @@ __all__ = ["PCC", "main"]
@device_logging_to_python({"device": "PCC"}) @device_logging_to_python({"device": "PCC"})
class PCC(hardware_device): class PCC(hardware_device):
"""
**Properties:**
- Device Property
OPC_Server_Name
- Type:'DevString'
OPC_Server_Port
- Type:'DevULong'
OPC_Time_Out
- Type:'DevDouble'
"""
# ----------------- # -----------------
# Device Properties # Device Properties
# ----------------- # -----------------
OPC_Server_Name = device_property( OPC_Server_Name = device_property(
dtype='DevString', dtype='DevString',
mandatory=True mandatory=True
...@@ -58,7 +44,8 @@ class PCC(hardware_device): ...@@ -58,7 +44,8 @@ class PCC(hardware_device):
dtype='DevDouble', dtype='DevDouble',
mandatory=True mandatory=True
) )
OPC_namespace = device_property(
OPC_Namespace = device_property(
dtype='DevString', dtype='DevString',
mandatory=False mandatory=False
) )
...@@ -66,32 +53,57 @@ class PCC(hardware_device): ...@@ -66,32 +53,57 @@ class PCC(hardware_device):
# ---------- # ----------
# Attributes # 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) 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) 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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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,)) 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_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_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_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:HBA_element_pwr_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) 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): def delete_device(self):
"""Hook to delete resources allocated in init_device. """Hook to delete resources allocated in init_device.
...@@ -100,7 +112,6 @@ class PCC(hardware_device): ...@@ -100,7 +112,6 @@ class PCC(hardware_device):
destructor and by the device Init command (a Tango built-in). destructor and by the device Init command (a Tango built-in).
""" """
self.debug_stream("Shutting down...") self.debug_stream("Shutting down...")
self.Off() self.Off()
self.debug_stream("Shut down. Good bye.") self.debug_stream("Shut down. Good bye.")
...@@ -111,24 +122,17 @@ class PCC(hardware_device): ...@@ -111,24 +122,17 @@ class PCC(hardware_device):
""" user code here. is called when the state is set to OFF """ """ user code here. is called when the state is set to OFF """
# Stop keep-alive # Stop keep-alive
self.opcua_connection.stop() self.OPCua_client.disconnect()
def initialise(self): def initialise(self):
""" user code here. is called when the state is set to INIT """ """ 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 #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 # map the attributes to the OPC ua comm client
for i in self.attr_list(): for i in self.attr_list():
...@@ -137,6 +141,16 @@ class PCC(hardware_device): ...@@ -137,6 +141,16 @@ class PCC(hardware_device):
except: except:
pass 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() self.OPCua_client.start()
# -------- # --------
......
from src.comms_client import * from src.comms_client import *
import opcua
__all__ = ["OPCUAConnection"] __all__ = ["OPCUAConnection"]
...@@ -39,7 +39,7 @@ class OPCUAConnection(CommClient): ...@@ -39,7 +39,7 @@ class OPCUAConnection(CommClient):
""" """
super().__init__(on_func, fault_func, streams, try_interval) super().__init__(on_func, fault_func, streams, try_interval)
self.client = Client(address, timeout) self.client = opcua.Client(address, timeout)
# Explicitly connect # Explicitly connect
if not self.connect(): if not self.connect():
...@@ -89,16 +89,19 @@ class OPCUAConnection(CommClient): ...@@ -89,16 +89,19 @@ class OPCUAConnection(CommClient):
try: try:
self.client.disconnect() self.client.disconnect()
except Exception as e: 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): def ping(self):
""" """
ping the client to make sure the connection with the client is still functional. ping the client to make sure the connection with the client is still functional.
""" """
try: 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: 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): def _setup_annotation(self, annotation):
""" """
...@@ -114,13 +117,12 @@ class OPCUAConnection(CommClient): ...@@ -114,13 +117,12 @@ class OPCUAConnection(CommClient):
elif isinstance(annotation, list): elif isinstance(annotation, list):
path = annotation path = annotation
else: 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: try:
node = self.obj.get_child(path) node = self.obj.get_child(path)
except Exception as e: 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: {} on server {}".format(path, self._servername())) from e
raise Exception("Could not get node: %s on server %s", path, self._servername()) from e
return node return node
......
...@@ -3,9 +3,6 @@ import socket ...@@ -3,9 +3,6 @@ import socket
import time import time
import numpy import numpy
import opcua
from opcua import Client
from tango import DevState from tango import DevState
......
...@@ -84,9 +84,9 @@ class hardware_device(Device): ...@@ -84,9 +84,9 @@ class hardware_device(Device):
""" """
self.set_state(DevState.INIT) self.set_state(DevState.INIT)
self.setup_value_dict() self.setup_value_dict()
self.initialise() self.initialise()
self.standby()
self.set_state(DevState.STANDBY)
@only_in_states([DevState.INIT]) @only_in_states([DevState.INIT])
def Standby(self): def Standby(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment