diff options
Diffstat (limited to 'lab_control/connection')
-rw-r--r-- | lab_control/connection/direct_connection.py | 2 | ||||
-rw-r--r-- | lab_control/connection/tcp_connection.py | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lab_control/connection/direct_connection.py b/lab_control/connection/direct_connection.py index 56a5cf3..8df1e42 100644 --- a/lab_control/connection/direct_connection.py +++ b/lab_control/connection/direct_connection.py @@ -10,7 +10,7 @@ class DirectConnection: def close(self) -> None: self.open = False - def send(self, request: str) -> str: + def send(self, request: str, responseExpected=True) -> str: return self.requestHandler(request) def checkConfiguration(self) -> None: diff --git a/lab_control/connection/tcp_connection.py b/lab_control/connection/tcp_connection.py new file mode 100644 index 0000000..6af710c --- /dev/null +++ b/lab_control/connection/tcp_connection.py @@ -0,0 +1,22 @@ +import socket + +class TCPConnection: + def __init__(self, ip: str, port: int): + self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self._socket.connect((address, port)) + + def configure(self, config: dict) -> None: + self._socket.settimeout(parameters["timeout"]) + + def send(self, request, responseExpected=True): + self._socket.sendall(request.encode()) + + if responseExpected: + try: + response = self._socket.recv(4096).decode() + except TimeoutError: + response = None + return response + + def checkConfiguration(self) -> None: + pass |