diff --git a/devices/clients/comms_client.py b/devices/clients/comms_client.py index 011e1e62180e85f6bc17d72a6ee31eb5871ecb50..6aa52ae42bf7bd9a2a22b2661784696fa95cbc74 100644 --- a/devices/clients/comms_client.py +++ b/devices/clients/comms_client.py @@ -21,9 +21,10 @@ class CommClient(Thread): def connect(self): """ Function used to connect to the client. + + Throws an Exception if the connection cannot be established. """ self.connected = True - return True def disconnect(self): """ diff --git a/devices/clients/opcua_client.py b/devices/clients/opcua_client.py index dc85a6f4fe645fdb9b7c47e46e2e78a42bbcf41f..e1aa0a87c59c738bc8d41c817cc8121aa7f93ad0 100644 --- a/devices/clients/opcua_client.py +++ b/devices/clients/opcua_client.py @@ -47,11 +47,7 @@ class OPCUAConnection(CommClient): self.client = Client(address, timeout) # Explicitly connect - if not self.connect(): - # hardware or infra is down -- needs fixing first - fault_func() - return - + self.connect() # determine namespace used try: @@ -79,13 +75,13 @@ class OPCUAConnection(CommClient): try: self.streams.debug_stream("Connecting to server %s", self._servername()) self.client.connect() - self.connected = True self.streams.debug_stream("Connected to %s. Initialising.", self._servername()) - return True except socket.error as e: self.streams.error_stream("Could not connect to server %s: %s", self._servername(), e) raise Exception("Could not connect to server %s", self._servername()) from e + super().connect() + def check_nodes(self): """ function purely for debugging/development only. Simply lists all top level nodes and the nodes below that diff --git a/devices/clients/statistics_client.py b/devices/clients/statistics_client.py index 5d45ac472b52ac2f024dfd4a338cb3d03f4d3c77..b66971b77ff3e67069b57b3b6db128a9be1dd120 100644 --- a/devices/clients/statistics_client.py +++ b/devices/clients/statistics_client.py @@ -36,10 +36,7 @@ class StatisticsClient(CommClient): super().__init__(fault_func, streams, try_interval) # Explicitly connect - if not self.connect(): - # hardware or infra is down -- needs fixing first - fault_func() - return + self.connect() def queue_fill_percentage(self): try: @@ -57,7 +54,7 @@ class StatisticsClient(CommClient): self.udp = UDPReceiver(self.host, self.port, self.queue, self.poll_timeout) self.statistics = self.statistics_collector_class(self.queue) - return super().connect() + super().connect() def ping(self): if not self.statistics.is_alive():