def _initialize(self):
'''TODO add docstring.'''
self.output.configure(dtype=self.dtype, shape=(self.nb_samples, self.nb_channels))
self.queue = Queue.Queue()
self.size = self.nb_channels * self.nb_samples * 2 # i.e. nb_chan * nb_step * size(uint16)
def recv_target(queue, size, host, port):
# Define the address of the input socket.
address = (host, port)
# Bind an input socket.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Create a connection to this address.
s.connect(address)
# Receive data.
while True:
try:
recv_string = s.recv(size, socket.MSG_WAITALL)
except socket.error as e:
if e.errno == errno.ECONNRESET:
# Discard error message.
break
else:
raise e
queue.put(recv_string)
# Prepare background thread for data acquisition.
args = (self.queue, self.size, self.host, self.port)
self.recv_thread = threading.Thread(target=recv_target, args=args)
self.recv_thread.deamon = True
# Launch background thread for data acquisition.
self.log.info("{n} starts listening for data on {f}...".format(n=self.name, f="%s:%d" %(self.host, self.port)))
self.recv_thread.start()
return
评论列表
文章目录