summaryrefslogtreecommitdiffstats
path: root/lab_control/connection
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2022-06-05 16:45:32 +0200
committerEddy Pedroni <eddy@0xf7.com>2022-06-05 16:45:50 +0200
commited42c1a47bc96f6453bb50008481d3467e9254e6 (patch)
tree300eab13aee99bb1322da61e8fe74243a32c59da /lab_control/connection
parent498b2543dc4336962c8c235ac7a0b41e175fde07 (diff)
Refactored SDS1000X-E unit tests
Diffstat (limited to 'lab_control/connection')
-rw-r--r--lab_control/connection/direct_connection.py2
-rw-r--r--lab_control/connection/tcp_connection.py22
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