improvements on secop.client.Client
- add unregister_callback (this is needed for the SECoP client in nicos) - improve error handling - imporve error handling in AsynTcp - also improve error handling on StringIO Change-Id: If4f3632a93cbc0e7fbc55a966e09fcc3e69c09b7 Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/22852 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
@ -23,8 +23,9 @@
|
||||
"""asynchronous connections
|
||||
|
||||
generic class for byte oriented communication
|
||||
includes implementation for TCP connections
|
||||
support for asynchronous communication, but may be used also for StringIO
|
||||
includes implementation for TCP and Serial connections
|
||||
support for asynchronous communication, but may be used also for
|
||||
synchronous IO (see secop.stringio.StringIO)
|
||||
"""
|
||||
|
||||
import socket
|
||||
@ -34,7 +35,7 @@ import ast
|
||||
from serial import Serial
|
||||
|
||||
from secop.lib import parseHostPort, tcpSocket, closeSocket
|
||||
from secop.errors import ConfigError
|
||||
from secop.errors import ConfigError, CommunicationFailedError
|
||||
|
||||
|
||||
class ConnectionClosed(ConnectionError):
|
||||
@ -133,7 +134,11 @@ class AsynTcp(AsynConn):
|
||||
if uri.startswith('tcp://'):
|
||||
# should be the case always
|
||||
uri = uri[6:]
|
||||
self.connection = tcpSocket(uri, self.defaultport, self.timeout)
|
||||
try:
|
||||
self.connection = tcpSocket(uri, self.defaultport, self.timeout)
|
||||
except (ConnectionRefusedError, socket.gaierror) as e:
|
||||
# indicate that retrying might make sense
|
||||
raise CommunicationFailedError(str(e))
|
||||
|
||||
def disconnect(self):
|
||||
if self.connection:
|
||||
@ -215,6 +220,7 @@ class AsynSerial(AsynConn):
|
||||
self.connection = Serial(dev, **options)
|
||||
except ValueError as e:
|
||||
raise ConfigError(e)
|
||||
# TODO: turn exceptions into ConnectionFailedError, where a retry makes sense
|
||||
|
||||
def disconnect(self):
|
||||
if self.connection:
|
||||
|
Reference in New Issue
Block a user