def test_ThreadPollInput(): app = pg.mkQApp() outstream = OutputStream() outstream.configure(**stream_spec) instream = InputStream() instream.connect(outstream) sender = ThreadSender(output_stream=outstream) poller = ThreadPollInput(input_stream=instream, return_data=True) global last_pos last_pos = 0 def on_new_data(pos, arr): assert arr.shape == (chunksize, nb_channel) global last_pos last_pos += chunksize assert last_pos == pos def terminate(): sender.wait() poller.stop() poller.wait() app.quit() sender.finished.connect(terminate) poller.new_data.connect(on_new_data) poller.start() sender.start() app.exec_()
class StreamMonitor(Node): """ Monitors activity on an input stream and prints details about packets received. """ _input_specs = {'signals': {}} def __init__(self, **kargs): Node.__init__(self, **kargs) def _configure(self): pass def _initialize(self): # There are many ways to poll for data from the input stream. In this # case, we will use a background thread to monitor the stream and emit # a Qt signal whenever data is available. self.poller = ThreadPollInput(self.input, return_data=True) self.poller.new_data.connect(self.data_received) def _start(self): self.poller.start() def data_received(self, ptr, data): print("Data received: %d %s %s" % (ptr, data.shape, data.dtype))
def test_ThreadPollInput(): app = pg.mkQApp() outstream = OutputStream() outstream.configure(**stream_spec) instream = InputStream() instream.connect(outstream) sender = ThreadSender(output_stream=outstream) poller = ThreadPollInput(input_stream=instream, return_data=True) global last_pos last_pos= 0 def on_new_data(pos, arr): assert arr.shape==(chunksize, nb_channel) global last_pos last_pos += chunksize assert last_pos==pos def terminate(): sender.wait() poller.stop() poller.wait() app.quit() sender.finished.connect(terminate) poller.new_data.connect(on_new_data) poller.start() sender.start() app.exec_()
def test_stream_splitter(): app = pg.mkQApp() stream_spec = dict(protocol='tcp', interface='127.0.0.1', port='*', transfermode='plaindata', streamtype='analogsignal', dtype='float32', shape=(-1, nb_channel), timeaxis=0, compression='', scale=None, offset=None, units='') outstream = OutputStream() outstream.configure(**stream_spec) sender = ThreadSender(output_stream=outstream) def on_new_data(pos, arr): assert arr.shape == (chunksize, 1) # print(pos, arr.shape) all_instream = [] all_poller = [] splitter = StreamSplitter() splitter.configure() splitter.input.connect(outstream) for name, output in splitter.outputs.items(): output.configure() instream = InputStream() instream.connect(output) poller = ThreadPollInput(input_stream=instream) poller.new_data.connect(on_new_data) all_instream.append(instream) all_poller.append(poller) splitter.initialize() def terminate(): sender.wait() splitter.stop() for poller in all_poller: poller.stop() poller.wait() app.quit() sender.terminated.connect(terminate) for poller in all_poller: poller.start() splitter.start() sender.start() app.exec_()
def test_streamconverter(): app = pg.mkQApp() stream_spec = dict(protocol='tcp', interface='127.0.0.1', port='*', transfermode='plaindata', streamtype='analogsignal', dtype='float32', shape=(-1, nb_channel), timeaxis = 0, compression ='', scale = None, offset = None, units = '') outstream = OutputStream() outstream.configure(**stream_spec) sender = ThreadSender(output_stream=outstream) stream_spec2 = dict(protocol='tcp', interface='127.0.0.1', port='*', transfermode='sharedarray', streamtype='analogsignal', dtype='float32', shape=(nb_channel, -1), timeaxis = 1, compression ='', scale = None, offset = None, units = '', sharedarray_shape = (nb_channel, chunksize*20), ring_buffer_method = 'double', ) conv = StreamConverter() conv.configure() conv.input.connect(outstream) conv.output.configure(**stream_spec2) conv.initialize() instream = InputStream() instream.connect(conv.output) global last_pos last_pos= 0 def on_new_data(pos, arr): assert arr is None global last_pos last_pos += chunksize assert last_pos==pos def terminate(): sender.wait() conv.stop() poller.stop() poller.wait() app.quit() poller = ThreadPollInput(input_stream=instream) sender.terminated.connect(terminate) poller.new_data.connect(on_new_data) poller.start() conv.start() sender.start() app.exec_()
def test_streamconverter(): app = pg.mkQApp() stream_spec = dict(protocol='tcp', interface='127.0.0.1', port='*', transfermode='plaindata', streamtype='analogsignal', dtype='float32', shape=(-1, nb_channel)) outstream = OutputStream() outstream.configure(**stream_spec) sender = ThreadSender(output_stream=outstream) stream_spec2 = dict(protocol='tcp', interface='127.0.0.1', port='*', transfermode='sharedmem', streamtype='analogsignal', dtype='float32', shape=(-1, nb_channel), buffer_size=1000, double=True, ) conv = StreamConverter() conv.configure() conv.input.connect(outstream) conv.output.configure(**stream_spec2) conv.initialize() instream = InputStream() instream.connect(conv.output) global last_pos last_pos= 0 def on_new_data(pos, arr): assert arr is None global last_pos last_pos += chunksize assert last_pos==pos def terminate(): sender.wait() #~ conv.stop() poller.stop() poller.wait() app.quit() poller = ThreadPollInput(input_stream=instream, return_data=None) sender.finished.connect(terminate) poller.new_data.connect(on_new_data) poller.start() conv.start() sender.start() app.exec_()
def test_stream_splitter(): app = pg.mkQApp() stream_spec = dict(protocol='tcp', interface='127.0.0.1', port='*', transfermode='plaindata', streamtype='analogsignal', dtype='float32', shape=(-1, nb_channel), timeaxis = 0, compression ='', scale = None, offset = None, units = '') outstream = OutputStream() outstream.configure(**stream_spec) sender = ThreadSender(output_stream=outstream) def on_new_data(pos, arr): assert arr.shape==(chunksize, 1) # print(pos, arr.shape) all_instream = [] all_poller = [] splitter = StreamSplitter() splitter.configure() splitter.input.connect(outstream) for name, output in splitter.outputs.items(): output.configure() instream = InputStream() instream.connect(output) poller = ThreadPollInput(input_stream=instream) poller.new_data.connect(on_new_data) all_instream.append(instream) all_poller.append(poller) splitter.initialize() def terminate(): sender.wait() splitter.stop() for poller in all_poller: poller.stop() poller.wait() app.quit() sender.terminated.connect(terminate) for poller in all_poller: poller.start() splitter.start() sender.start() app.exec_()
def test_stream_splitter(): app = pg.mkQApp() outstream = OutputStream() outstream.configure(**stream_spec) sender = ThreadSender(output_stream=outstream) def on_new_data(pos, arr): assert arr.shape[0] == chunksize assert not arr.flags['C_CONTIGUOUS'] all_instream = [] all_poller = [] splitter = ChannelSplitter() splitter.configure(output_channels={ 'out0': [0, 1, 2], 'out1': [1, 4, 9, 12] }) splitter.input.connect(outstream) for name, output in splitter.outputs.items(): output.configure() instream = InputStream() instream.connect(output) poller = ThreadPollInput(input_stream=instream, return_data=True) poller.new_data.connect(on_new_data) all_instream.append(instream) all_poller.append(poller) splitter.initialize() def terminate(): sender.wait() splitter.stop() for poller in all_poller: poller.stop() poller.wait() app.quit() sender.finished.connect(terminate) for poller in all_poller: poller.start() splitter.start() sender.start() app.exec_()
def test_stream_splitter(): app = pg.mkQApp() outstream = OutputStream() outstream.configure(**stream_spec) sender = ThreadSender(output_stream=outstream) def on_new_data(pos, arr): assert arr.shape[0]==chunksize assert not arr.flags['C_CONTIGUOUS'] all_instream = [] all_poller = [] splitter = ChannelSplitter() splitter.configure(output_channels = { 'out0' : [0,1,2], 'out1' : [1,4,9, 12] }) splitter.input.connect(outstream) for name, output in splitter.outputs.items(): output.configure() instream = InputStream() instream.connect(output) poller = ThreadPollInput(input_stream=instream, return_data=True) poller.new_data.connect(on_new_data) all_instream.append(instream) all_poller.append(poller) splitter.initialize() def terminate(): sender.wait() splitter.stop() for poller in all_poller: poller.stop() poller.wait() app.quit() sender.finished.connect(terminate) for poller in all_poller: poller.start() splitter.start() sender.start() app.exec_()
def test_ChunkResizer(): app = pg.mkQApp() outstream = OutputStream() outstream.configure(**stream_spec) sender = ThreadSender(output_stream=outstream) chunkresizer = ChunkResizer() chunkresizer.configure(chunksize=33) chunkresizer.input.connect(outstream) chunkresizer.output.configure() chunkresizer.initialize() def on_new_data(pos, arr): #~ print('recv', arr.shape, pos) assert arr.shape[0] == 33 instream = InputStream() instream.connect(chunkresizer.output) poller = ThreadPollInput(input_stream=instream, return_data=True) poller.new_data.connect(on_new_data) def terminate(): sender.wait() chunkresizer.stop() poller.stop() poller.wait() app.quit() sender.finished.connect(terminate) poller.start() chunkresizer.start() sender.start() app.exec_()
def test_streamconverter(): app = pg.mkQApp() stream_spec = dict(protocol='tcp', interface='127.0.0.1', port='*', transfermode='plaindata', streamtype='analogsignal', dtype='float32', shape=(-1, nb_channel), timeaxis=0, compression='', scale=None, offset=None, units='') outstream = OutputStream() outstream.configure(**stream_spec) sender = ThreadSender(output_stream=outstream) stream_spec2 = dict( protocol='tcp', interface='127.0.0.1', port='*', transfermode='sharedarray', streamtype='analogsignal', dtype='float32', shape=(nb_channel, -1), timeaxis=1, compression='', scale=None, offset=None, units='', sharedarray_shape=(nb_channel, chunksize * 20), ring_buffer_method='double', ) conv = StreamConverter() conv.configure() conv.input.connect(outstream) conv.output.configure(**stream_spec2) conv.initialize() instream = InputStream() instream.connect(conv.output) global last_pos last_pos = 0 def on_new_data(pos, arr): assert arr is None global last_pos last_pos += chunksize assert last_pos == pos def terminate(): sender.wait() conv.stop() poller.stop() poller.wait() app.quit() poller = ThreadPollInput(input_stream=instream) sender.terminated.connect(terminate) poller.new_data.connect(on_new_data) poller.start() conv.start() sender.start() app.exec_()
def _initialize(self): # There are many ways to poll for data from the input stream. In this # case, we will use a background thread to monitor the stream and emit # a Qt signal whenever data is available. self.poller = ThreadPollInput(self.input, return_data=True) self.poller.new_data.connect(self.data_received)