From 799fd9b98ab47129f650b4f4b5228305b6bea5f2 Mon Sep 17 00:00:00 2001 From: thijs snijder <snijder@astron.nl> Date: Mon, 17 May 2021 14:33:01 +0200 Subject: [PATCH] added pass function in attribute wrapper and calls to it in the device configure_for_initialise --- devices/APSCTL.py | 4 +++- devices/PCC.py | 6 ++++-- devices/SDP.py | 4 +++- devices/SNMP.py | 9 +++++++-- devices/ini_device.py | 7 ++++++- devices/util/attribute_wrapper.py | 13 +++++++++---- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/devices/APSCTL.py b/devices/APSCTL.py index f1ea50f30..62bc56f85 100644 --- a/devices/APSCTL.py +++ b/devices/APSCTL.py @@ -166,7 +166,9 @@ class APSCTL(hardware_device): try: i.set_comm_client(self.OPCua_client) except: - self.debug_stream("error in getting APSCTL attribute: {} from client".format(i)) + # use the pass function instead of setting read/write fails + i.set_pass_func(self.OPCua_client) + self.error_stream("error in getting APSCTL attribute: {} from client".format(i)) self.OPCua_client.start() diff --git a/devices/PCC.py b/devices/PCC.py index ff0ed0914..bb35a0b6c 100644 --- a/devices/PCC.py +++ b/devices/PCC.py @@ -140,12 +140,14 @@ class PCC(hardware_device): self.OPCua_client = OPCUAConnection("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), "http://lofar.eu", self.OPC_Time_Out, self.Fault, self) - # map the attributes to the OPC ua comm client + # map an access helper class for i in self.attr_list(): try: i.set_comm_client(self.OPCua_client) except: - pass + # use the pass function instead of setting read/write fails + i.set_pass_func(self.OPCua_client) + self.error_stream("error in getting PCC attribute: {} from client".format(i)) self.OPCua_client.start() diff --git a/devices/SDP.py b/devices/SDP.py index 19f21fc93..0e69a4362 100644 --- a/devices/SDP.py +++ b/devices/SDP.py @@ -139,7 +139,9 @@ class SDP(hardware_device): try: i.set_comm_client(self.OPCua_client) except: - self.debug_stream("error in getting SDP attribute: {} from client".format(i)) + # use the pass function instead of setting read/write fails + i.set_pass_func(self.OPCua_client) + self.error_stream("error in getting SDP attribute: {} from client".format(i)) self.OPCua_client.start() diff --git a/devices/SNMP.py b/devices/SNMP.py index 8b5d4a21c..c9a8337d5 100644 --- a/devices/SNMP.py +++ b/devices/SNMP.py @@ -88,9 +88,14 @@ class SNMP(hardware_device): # set up the SNMP ua client self.snmp_manager = SNMP_client(self.SNMP_community, self.SNMP_host, self.SNMP_timeout, self.Fault, self) - # map the attributes to the OPC ua comm client + # map an access helper class for i in self.attr_list(): - i.set_comm_client(self.snmp_manager) + try: + i.set_comm_client(self.snmp_manager) + except: + # use the pass function instead of setting read/write fails + i.set_pass_func(self.snmp_manager) + self.error_stream("error in getting SNMP attribute: {} from client".format(i)) self.snmp_manager.start() diff --git a/devices/ini_device.py b/devices/ini_device.py index 0b8161183..6be6b1a61 100644 --- a/devices/ini_device.py +++ b/devices/ini_device.py @@ -108,7 +108,12 @@ class ini_device(hardware_device): # map an access helper class for i in self.attr_list(): - i.set_comm_client(self.ini_client) + try: + i.set_comm_client(self.ini_client) + except: + # use the pass function instead of setting read/write fails + i.set_pass_func(self.ini_client) + self.error_stream("error in getting ini attribute: {} from client".format(i)) self.ini_client.start() diff --git a/devices/util/attribute_wrapper.py b/devices/util/attribute_wrapper.py index b27187cda..73e892322 100644 --- a/devices/util/attribute_wrapper.py +++ b/devices/util/attribute_wrapper.py @@ -138,9 +138,14 @@ class attribute_wrapper(attribute): def pass_func(value=None): pass - logger.error("Exception while setting %s attribute with annotation: '%s' read/write functions. using pass function instead to to keep running", client.__class__.__name__, self.comms_annotation) + logger.error("Exception while setting {} attribute with annotation: '{}'".format(client.__class__.__name__, self.comms_annotation)) + raise Exception("Exception while setting %s attribute with annotation: '%s'", client.__class__.__name__, self.comms_annotation) from e - self.read_function = pass_func - self.write_function = pass_func + def set_pass_func(self, client): + def pass_func(value=None): + pass - raise Exception("Exception while setting comm_client read/write functions. using pass function instead. %s") from e + logger.debug("using pass function for {} attribute with annotation: {}".format(client.__class__.__name__, self.comms_annotation)) + + self.read_function = pass_func + self.write_function = pass_func -- GitLab