From 4bb11e249d8a4fe41c17462a92ebb89e5b1c40b4 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 26 Feb 2020 11:36:28 +0100 Subject: [PATCH] stringio now works with serial connections also allow SECoP client connections via serial Change-Id: I10c02532a9f8e9b8f16599b98c439742da6d8f5c Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/22525 Tested-by: JenkinsCodeReview Reviewed-by: Markus Zolliker --- secop/lib/asynconn.py | 128 +++++++++++++++++++++++++++++++++++++----- secop/stringio.py | 124 +++++++++------------------------------- 2 files changed, 141 insertions(+), 111 deletions(-) diff --git a/secop/lib/asynconn.py b/secop/lib/asynconn.py index d7c3e26..5569fe2 100644 --- a/secop/lib/asynconn.py +++ b/secop/lib/asynconn.py @@ -16,21 +16,25 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Module authors: -# Enrico Faulhaber # Markus Zolliker # # ***************************************************************************** -"""asynchonous connections +"""asynchronous connections generic class for byte oriented communication includes implementation for TCP connections +support for asynchronous communication, but may be used also for StringIO """ import socket +import select import time +import ast +from serial import Serial from secop.lib import parseHostPort, tcpSocket, closeSocket +from secop.errors import ConfigError class ConnectionClosed(ConnectionError): @@ -43,7 +47,7 @@ class AsynConn: connection = None # is not None, if connected defaultport = None - def __new__(cls, uri): + def __new__(cls, uri, end_of_line=b'\n'): scheme = uri.split('://')[0] iocls = cls.SCHEME_MAP.get(scheme, None) if not iocls: @@ -51,12 +55,19 @@ class AsynConn: try: host_port = parseHostPort(uri, cls.defaultport) except (ValueError, TypeError, AssertionError): + if 'COM' in uri: + raise ValueError("the correct uri for a COM port is: " + "'serial://COM[?