diff --git a/devices/APSCTL.py b/devices/APSCTL.py index f1ea50f303e608230aaeba346dbd99bde8480773..030f5cdcbb70af81bf6621dd0fc1277414ed5714 100644 --- a/devices/APSCTL.py +++ b/devices/APSCTL.py @@ -149,9 +149,11 @@ class APSCTL(hardware_device): @log_exceptions() def configure_for_off(self): """ user code here. is called when the state is set to OFF """ - # Stop keep-alive - self.opcua_connection.stop() + try: + self.opcua_connection.stop() + except Exception as e: + self.warn_stream("Exception while stopping OPC ua connection in configure_for_off function: {}. Exception ignored".format(e)) @log_exceptions() def configure_for_initialise(self): @@ -165,8 +167,10 @@ class APSCTL(hardware_device): for i in self.attr_list(): try: i.set_comm_client(self.OPCua_client) - except: - self.debug_stream("error in getting APSCTL attribute: {} from client".format(i)) + except Exception as e: + # use the pass function instead of setting read/write fails + i.set_pass_func() + self.warn_stream("error while setting the APSCTL attribute {} read/write function. {}".format(i, e)) self.OPCua_client.start() diff --git a/devices/PCC.py b/devices/PCC.py index aa4a474b7d76226ae66793043d7eea0306ad3af9..e75c65045f000711d76f6f0998bf8e92c071da53 100644 --- a/devices/PCC.py +++ b/devices/PCC.py @@ -122,7 +122,10 @@ class PCC(hardware_device): def configure_for_off(self): """ user code here. is called when the state is set to OFF """ # Stop keep-alive - self.OPCua_client.stop() + try: + self.opcua_connection.stop() + except Exception as e: + self.warn_stream("Exception while stopping OPC ua connection in configure_for_off function: {}. Exception ignored".format(e)) @log_exceptions() def configure_for_initialise(self): @@ -139,12 +142,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 + except Exception as e: + # use the pass function instead of setting read/write fails + i.set_pass_func() + self.warn_stream("error while setting the PCC attribute {} read/write function. {}".format(i, e)) self.OPCua_client.start() diff --git a/devices/SDP.py b/devices/SDP.py index f3fbdcabacea0cd76760be08f2190f1134c76da2..b54abece1c0a2b55698343fbd076ea65a6bd83ea 100644 --- a/devices/SDP.py +++ b/devices/SDP.py @@ -127,7 +127,10 @@ class SDP(hardware_device): """ user code here. is called when the state is set to OFF """ # Stop keep-alive - self.opcua_connection.stop() + try: + self.opcua_connection.stop() + except Exception as e: + self.warn_stream("Exception while stopping OPC ua connection in configure_for_off function: {}. Exception ignored".format(e)) @log_exceptions() def configure_for_initialise(self): @@ -139,7 +142,13 @@ class SDP(hardware_device): # map an access helper class for i in self.attr_list(): - i.set_comm_client(self.OPCua_client) + try: + i.set_comm_client(self.OPCua_client) + except Exception as e: + # use the pass function instead of setting read/write fails + i.set_pass_func() + self.warn_stream("error while setting the SDP attribute {} read/write function. {}".format(i, e)) + pass self.OPCua_client.start() diff --git a/devices/SNMP.py b/devices/SNMP.py index 8b5d4a21c85cebbc562bd22baf5afec5e37b86d9..db748639ef3c784792b0d5e2211019b50bac1e9f 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 Exception as e: + # use the pass function instead of setting read/write fails + i.set_pass_func() + self.warn_stream("error while setting the SNMP attribute {} read/write function. {}".format(i, e)) self.snmp_manager.start() diff --git a/devices/ini_device.py b/devices/ini_device.py index 0b81611830e9ed14e76141ee583a1e6a7ddb8c60..dbc6e6159409449cfa7f5577e06eaa84e0620a06 100644 --- a/devices/ini_device.py +++ b/devices/ini_device.py @@ -108,7 +108,13 @@ 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 Exception as e: + # use the pass function instead of setting read/write fails + i.set_pass_func() + + self.warn_stream("error while setting the ini attribute {} read/write function. {}".format(i, e)) self.ini_client.start() diff --git a/devices/util/attribute_wrapper.py b/devices/util/attribute_wrapper.py index b27187cda57a7d7238a677a085867011ad0ccb23..d4584f01b78b22d0ee634d91963d2b80adcd29f4 100644 --- a/devices/util/attribute_wrapper.py +++ b/devices/util/attribute_wrapper.py @@ -135,12 +135,15 @@ class attribute_wrapper(attribute): try: self.read_function, self.write_function = client.setup_attribute(self.comms_annotation, self) except Exception as e: - 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, e)) + 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): + 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(self.comms_annotation)) + + self.read_function = pass_func + self.write_function = pass_func