coredevice: add comm_tcp

This commit is contained in:
Sebastien Bourdeauducq 2015-04-10 01:22:03 +08:00
parent f427041ae9
commit 88e0aae16d

View File

@ -0,0 +1,36 @@
import logging
import socket
from artiq.coredevice.comm_generic import CommGeneric
from artiq.language.db import *
logger = logging.getLogger(__name__)
class Comm(CommGeneric, AutoDB):
class DBKeys:
host = Argument()
port = Argument(1381)
def open(self):
if hasattr(self, "socket"):
return
self.socket = socket.create_connection((self.host, self.port))
logger.debug("connected to host %s on port %d", self.host, self.port)
def close(self):
if not hasattr(self, "socket"):
return
self.socket.close()
del self.socket
logger.debug("disconnected")
def read(self, length):
r = bytes()
while len(r) < length:
r += self.socket.recv(min(8192, length - len(r)))
return r
def write(self, data):
self.socket.sendall(data)