From 0832c71a665c06c98876d398a3e013671b16b8cc Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 18 Dec 2015 18:22:50 +0800 Subject: [PATCH] coredevice/comm_tcp: support retrieving analyzer data --- artiq/coredevice/comm_tcp.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/artiq/coredevice/comm_tcp.py b/artiq/coredevice/comm_tcp.py index cd8d97e9a..1ad7d3e8b 100644 --- a/artiq/coredevice/comm_tcp.py +++ b/artiq/coredevice/comm_tcp.py @@ -24,20 +24,26 @@ def set_keepalive(sock, after_idle, interval, max_fails): sys.platform) +def initialize_connection(host, port): + sock = socket.create_connection((host, port), 5.0) + sock.settimeout(None) + set_keepalive(sock, 3, 2, 3) + logger.debug("connected to host %s on port %d", host, port) + sock.sendall(b"ARTIQ coredev\n") + return sock + + class Comm(CommGeneric): - def __init__(self, dmgr, host, port=1381): + def __init__(self, dmgr, host, port=1381, port_analyzer=1382): super().__init__() self.host = host self.port = port + self.port_analyzer = port_analyzer def open(self): if hasattr(self, "socket"): return - self.socket = socket.create_connection((self.host, self.port), 5.0) - self.socket.settimeout(None) - set_keepalive(self.socket, 3, 2, 3) - logger.debug("connected to host %s on port %d", self.host, self.port) - self.write(b"ARTIQ coredev\n") + self.socket = initialize_connection(self.host, self.port) def close(self): if not hasattr(self, "socket"): @@ -57,3 +63,14 @@ class Comm(CommGeneric): def write(self, data): self.socket.sendall(data) + + def get_analyzer_dump(self): + sock = initialize_connection(self.host, self.port_analyzer) + r = bytes() + while True: + buf = sock.recv(8192) + if not buf: + break + r += buf + sock.close() + return r