Skip to content
Snippets Groups Projects
Commit 25a05c06 authored by Taya Snijder's avatar Taya Snijder
Browse files

Merge branch 'master' into L2SS-334_2021-10-21_replace_streams_with_logger

parents 00257761 ea573fcb
No related branches found
No related tags found
1 merge request!164Resolve L2SS-334 "2021 10 21 replace streams with logger"
......@@ -62,9 +62,10 @@ class CommClient(AbstractCommClient, 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):
"""
......@@ -73,22 +74,15 @@ class CommClient(AbstractCommClient, Thread):
self.connected = False
def run(self):
# Explicitly connect
if not self.connect():
# hardware or infra is down -- needs fixing first
self.fault_func()
return
self.stopping = False
while not self.stopping:
# keep trying to connect
if not self.connected:
if self.connect():
pass
else:
# we retry only once, to catch exotic network issues. if the infra or hardware is down,
# our device cannot help, and must be reinitialised after the infra or hardware is fixed.
# we (re)try only once, to catch exotic network issues. if the infra or hardware is down,
# our device cannot help, and must be reinitialised after the infra or hardware is fixed.
try:
self.connect()
except Exception as e:
self.streams.error_stream("Fault condition in communication detected.", e)
self.fault_func()
return
......
......@@ -59,7 +59,6 @@ class OPCUAConnection(AsyncCommClient):
try:
await self.client.connect()
self.connected = True
except (socket.error, IOError, OSError) as e:
raise IOError(f"Could not connect to OPC-UA server {self._servername()}") from e
......
......@@ -24,10 +24,7 @@ class test_client(CommClient):
super().__init__(fault_func, try_interval)
# Explicitly connect
if not self.connect():
# hardware or infra is down -- needs fixing first
fault_func()
return
self.connect()
def connect(self):
"""
......@@ -36,7 +33,6 @@ class test_client(CommClient):
logger.debug("the example client doesn't actually connect to anything silly")
self.connected = True # set connected to true
return True # if succesfull, return true. otherwise return false
def disconnect(self):
self.connected = False # always force a reconnect, regardless of a successful disconnect
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment