def _stream_debug(self): info = pylsl.stream_info('Debug', 'EEG', self.channel_count, self.nominal_srate, pylsl.cf_float32, 'dsffwerwer') outlet = pylsl.stream_outlet(info) print('DebudStream: Streaming start...') path_rest = 'C:/Workspace/SpeechMapping/SpeechMappingv0_3/data/Sysoeva/10_10_19/data_rest/experiment_data.h5' path_actions = 'C:/Workspace/SpeechMapping/SpeechMappingv0_3/data/Sysoeva/10_10_19/data_actions/experiment_data.h5' path_objects = 'C:/Workspace/SpeechMappingv0_3/data/Sysoeva/10_10_19/data_objects/experiment_data.h5' paths = [path_rest, path_actions, path_objects] time.sleep(3) for i in range(len(paths)): with h5py.File(paths[i], "r") as file: data = file['protocol1']['raw_data'] data_length = data.shape[0] index = 0 start_time = time.time() current_time = time.time() while (time.time() - start_time < self.stream_time) and index < data_length: if time.time() - current_time > 1 / 2048: current_time = time.time() sample = data[index, :68] outlet.push_sample(sample) index += 1 if index % 100 == 0: print('Index: ', index) time.sleep(0.0001) time.sleep(3) print('DebudStream: Streaming stop...')
def Ni_data_collection(): streams = pylsl.resolve_stream() info = pylsl.stream_info('Force', 'Data', 1, 1000, 'float32') outlet = pylsl.stream_outlet(info) with nidaqmx.Task() as task: task.ai_channels.add_ai_voltage_chan("Dev1/ai0") while True: sample = pylsl.vectorf([task.read()]) outlet.push_sample(sample) time.sleep(0.01)
def handle_config(self, timestamp, data_obj): # Configure the LSL streams eeg_info = pylsl.stream_info("Interaxon","EEG", data_obj.eeg_channel_count, data_obj.eeg_sample_frequency_hz, pylsl.cf_float32, "Muse-EEG-" + data_obj.mac_addr) eeg_info.desc().append_child_value("manufacturer", "Interaxon") channels = eeg_info.desc().append_child("channels") for c in data_obj.eeg_channel_layout.split(): channels.append_child("channel").append_child_value("label",c).append_child_value("unit","microvolts").append_child_value("type","EEG") # outgoing buffer size to 360 seconds (max.) and the transmission chunk size to 32 samples self.__outlets["EEG"] = pylsl.stream_outlet(eeg_info, 360, 32) acc_info = pylsl.stream_info("Interaxon","Accelerometer", 3, 50, pylsl.cf_int32, "Muse-AC-" + data_obj.mac_addr) acc_info.desc().append_child_value("manufacturer", "Interaxon") channels = acc_info.desc().append_child("channels") for c in ['x', 'y', 'z']: channels.append_child("channel").append_child_value("label",c).append_child_value("unit","4/1023g").append_child_value("type","Accelerometer") # outgoing buffer size to 360 seconds (max.) and the transmission chunk size to 32 samples self.__outlets["ACC"] = pylsl.stream_outlet(acc_info, 360, 32)
def _stream(self): info = pylsl.stream_info('Debug', 'EEG', self.channel_count, self.nominal_srate, pylsl.cf_float32, 'dsffwerwer') outlet = pylsl.stream_outlet(info) print('DebudStream: Streaming start...') start_time = time.time() current_time = time.time() while (time.time() - start_time < self.stream_time): if time.time() - current_time > self.seconnds_per_sample: current_time = time.time() sample = [random.random() for i in range(self.channel_count)] outlet.push_sample(sample) #time.sleep(0.0002) time.sleep(0.0001) print('DebudStream: Streaming stop...')
def __init__(self, lslInputType="EEG", lslOutputType="POWER", outputRate=20, bufferSize=250, freqBand='Alpha'): self.bufferSize = bufferSize self.outputRate = outputRate self.freqBand = freqBand self.lslInputType = lslInputType self.stream = self.findStream() if self.stream is None: return self.inputRate = self.stream.nominal_srate() self.channels = self.stream.channel_count() self.buff = np.zeros((self.bufferSize, self.channels)) # first create a new stream info (here we set the name to BioSemi, the content-type to EEG, 8 channels, 100 Hz, and float-valued data) # The last value would be the serial number of the device or some other more or less locally unique identifier for the stream as far as available (you could also omit it but interrupted connections wouldn't auto-recover). self.outputInfo = pylsl.stream_info('EEGpower', 'Power', self.channels, self.outputRate, pylsl.cf_float32, 'PowerAnalyzer')
info = pylsl.stream_info('Force', 'Data', 1, 1000, 'float32') outlet = pylsl.stream_outlet(info) with nidaqmx.Task() as task: task.ai_channels.add_ai_voltage_chan("Dev1/ai0") while True: sample = pylsl.vectorf([task.read()]) outlet.push_sample(sample) time.sleep(0.01) Ni_collect_proccess = multiprocessing.Process(target=Ni_data_collection) #experiment_proccess= multiprocessing.Process(target=start_experiment) if __name__ == '__main__': trigg_info = pylsl.stream_info('Markers', 'Markers', 1, 0, 'string') trigg_outlet = pylsl.stream_outlet(trigg_info) app = App(LabRecorder_path, EEG_module_path, impedence_path, Ni_collect_proccess) app.root.mainloop() # message if EEG is not activated if app.EEG_var == 0: root2 = tk.Tk() root2.withdraw() result = tk.messagebox.askokcancel( title=None, message='No EEG Signal. \nWould you like to procceed?', ) if result == False: quit()
''' Created on Jul 10, 2012 @author: SCCN ''' from pylink import * import pylsl,socket, time if __name__ == '__main__': outlet = None try: info = pylsl.stream_info("EyeLink","Gaze",9,100,pylsl.cf_float32,"eyelink-" + socket.gethostname()); outlet = pylsl.stream_outlet(info) print "Established LSL outlet." except: print "Could not create LSL outlet." while True: try: print "Trying to connect to EyeLink tracker..." try: tracker = EyeLink("255.255.255.255") print "Established a passive connection with the eye tracker." except: tracker = EyeLink("100.1.1.1") print "Established a primary connection with the eye tracker." beginRealTimeMode(100)
import sys; sys.path.append('..') # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program) import pylsl import random import time # first create a new stream info (here we set the name to MyMarkerStream, the content-type to Markers, 1 channel, irregular sampling rate, and string-valued data) # The last value would be the locally unique identifier for the stream as far as available, e.g. program-scriptname-subjectnumber (you could also omit it but interrupted connections wouldn't auto-recover). # The important part is that the content-type is set to 'Markers', because then other programs will know how to interpret the content info = pylsl.stream_info('MyMarkerStream','Markers',1,0,pylsl.cf_string,'dgeyurtutu567sdf'); # next make an outlet outlet = pylsl.stream_outlet(info) print("now sending markers...") markernames = ['Test', 'Blah', 'Marker', 'XXX', 'Testtest', 'Test-1-2-3'] while True: # choose a marker string randomly and store it as a pylsl.vectorstr (note that this is actually a list since there can be multiple channels in the sample, even though it is of little use for markers) mysample = pylsl.vectorstr([ random.choice(markernames) ]) # now send it and wait for a bit outlet.push_sample(mysample) time.sleep(random.random()*3)
def CreateMrkStream(): info = pylsl.stream_info('P300_Markers', 'Markers', 1, 0, pylsl.cf_string, 'unsampledStream'); outlet = pylsl.stream_outlet(info, 1, 1) return outlet;
import sys; sys.path.append('..') # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program) import pylsl import random import time from PIL import Image import struct info = pylsl.stream_info('VideoFrameCommandStream','Markers',1,0,pylsl.cf_string,'dgeyurtutu567sdf'); outlet = pylsl.stream_outlet(info) print("looking for video frame stream...") streams = pylsl.resolve_stream('type','VideoRaw') # create a new inlet to read from the stream inlet = pylsl.stream_inlet(streams[0]) print("now sending markers...") flatFrame = pylsl.vectori() i=0 while True: # choose a marker string randomly and store it as a pylsl.vectorstr (note that this is actually a list since there can be multiple channels in the sample, even though it is of little use for markers) mysample = pylsl.vectorstr([ 'Request Image' ]) # now send it and wait for a bit outlet.push_sample(mysample) if(inlet.pull_sample(flatFrame,1)): print 'got frame' buf = struct.pack('b'*len(flatFrame), *flatFrame) #It is possible to load the width and height from the stream header, but not implemented here.
from Tkinter import * import random, pylsl from pylsl import stream_inlet, stream_outlet, stream_info info = stream_info('RandomData', 'EEG', 4, 50, pylsl.cf_int32, 'RandomDev123') outlet = stream_outlet(info) inlet = stream_inlet(info) inlet.open_stream() WIDTH = 800 HEIGHT = 600 SEG_SIZE = 20 IN_GAME = True def create_block(): global BLOCK posx = SEG_SIZE * random.randint(1, (WIDTH-SEG_SIZE) / SEG_SIZE) posy = SEG_SIZE * random.randint(1, (HEIGHT-SEG_SIZE) / SEG_SIZE) BLOCK = c.create_oval(posx, posy, posx+SEG_SIZE, posy+SEG_SIZE, fill="red") def main(): global IN_GAME if IN_GAME: s.move() head_coords = c.coords(s.segments[-1].instance) x1, y1, x2, y2 = head_coords insample = pylsl.vectorf() inlet_list = [] while inlet.samples_available(): inlet.pull_sample(insample)
''' Created on Jul 10, 2012 @author: SCCN ''' from pylink import * import pylsl, socket, time if __name__ == '__main__': outlet = None try: info = pylsl.stream_info("EyeLink", "Gaze", 9, 100, pylsl.cf_float32, "eyelink-" + socket.gethostname()) outlet = pylsl.stream_outlet(info) print "Established LSL outlet." except: print "Could not create LSL outlet." while True: try: print "Trying to connect to EyeLink tracker..." try: tracker = EyeLink("255.255.255.255") print "Established a passive connection with the eye tracker." except: tracker = EyeLink("100.1.1.1") print "Established a primary connection with the eye tracker." beginRealTimeMode(100) getEYELINK().startRecording(1, 1, 1, 1)
import pylsl import time try: from emotiv import epoc except ImportError: sys.path.insert(0, "..") from emotiv import epoc if __name__ == '__main__': headset = epoc.EPOC() print "Found headset with serial number: ", headset.serial_number info = pylsl.stream_info('Emotiv EEG', 'EEG', len(headset.channel_mask), headset.sampling_rate, pylsl.cf_int16, str(headset.serial_number)) info_desc = info.desc() info_desc.append_child_value("manufacturer", "Emotiv") channels = info_desc.append_child("channels") for ch in headset.channel_mask: channels.append_child("channel").append_child_value( "label", ch).append_child_value("unit", "microvolts").append_child_value( "type", "EEG") # Outgoing buffer size = 360 seconds, transmission chunk size = 32 samples outlet = pylsl.stream_outlet(info, 1, 32)
@author: SCCN ''' from pylink import * import pylsl, socket, time import msvcrt if __name__ == '__main__': outlet = None SR = 500 edfFileName = "TRIAL.edf" try: #info = pylsl.stream_info("EyeLink","Gaze",9,500,pylsl.cf_float32,"eyelink-" + socket.gethostname()); info = pylsl.stream_info("EyeLink", "Gaze", 10, SR, pylsl.cf_double64, "eyelink-" + socket.gethostname()) channels = info.desc().append_child("channels") channels.append_child("channel") \ .append_child_value("label", "leftEyeX") \ .append_child_value("type", "eyetracking") channels.append_child("channel") \ .append_child_value("label", "leftEyeY") \ .append_child_value("type", "eyetracking") channels.append_child("channel") \ .append_child_value("label", "rightEyeX") \ .append_child_value("type", "eyetracking") channels.append_child("channel") \ .append_child_value("label", "rightEyeY") \ .append_child_value("type", "eyetracking")
# Filename: pylsl_outlet.py # Author: Zhiguo Wang # Date: 11/7/2020 # # Description: # Streaming gaze data with an LSL data outlet import pylink import pylsl # Open a data outlet to stream data info = pylsl.stream_info("EyeLink", "Gaze", 3, 500, pylsl.cf_float32, "eyelink") outlet = pylsl.stream_outlet(info) # Connect to the tracker tracker = EyeLink("100.1.1.1") # Set sample rate to 500 Hz tracker.sendCommand('sample_rate 500') # Start recording tracker.startRecording(1, 1, 1, 1) print("Retrieving and streaming samples...") while True: smp = tracker.getNewestSample() if smp is not None: now = pylsl.local_clock() em_sample = [0, 0, 0] if smp.isLeftSample(): em_sample[0:2] = smp.getLeftEye().getGaze()
import sys; sys.path.append('..') # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program) import pylsl import random import time # first create a new stream info (here we set the name to BioSemi, the content-type to EEG, 8 channels, 100 Hz, and float-valued data) # The last value would be the serial number of the device or some other more or less locally unique identifier for the stream as far as available (you could also omit it but interrupted connections wouldn't auto-recover). info = pylsl.stream_info('BioSemi','EEG',8,100,pylsl.cf_float32,'dsffwerwer'); # append some meta-data info.desc().append_child_value("manufacturer","BioSemi") channels = info.desc().append_child("channels") for c in ["C3","C4","Cz","FPz","POz","CPz","O1","O2"]: channels.append_child("channel").append_child_value("name",c).append_child_value("unit","microvolts").append_child_value("type","EEG") # next make an outlet; we set the outgoing buffer size to 360 seconds (max.) and the transmission chunk size to 32 samples outlet = pylsl.stream_outlet(info,360,32) print("now sending data...") while True: # make a new random 8-channel sample; this is converted into a pylsl.vectorf (the data type that is expected by push_sample) mysample = pylsl.vectorf([random.random(),random.random(),random.random(),random.random(),random.random(),random.random(),random.random(),random.random()]) # get a time stamp in seconds (we might modify this time stamp based on the true age of the sample, e.g. if it came from a measurement device, in case we can determine it) now = pylsl.local_clock() # now send it and wait for a bit outlet.push_sample(mysample,now) time.sleep(0.01)
def CreateMrkStream(): info = pylsl.stream_info('SegSpeller_Markers', 'Markers', 1, 0, pylsl.cf_string, 'segspeller') return pylsl.stream_outlet(info)
@author: SCCN ''' from pylink import * import pylsl,socket, time import msvcrt if __name__ == '__main__': outlet = None SR = 500 edfFileName = "TRIAL.edf" try: #info = pylsl.stream_info("EyeLink","Gaze",9,500,pylsl.cf_float32,"eyelink-" + socket.gethostname()); info = pylsl.stream_info("EyeLink","Gaze",10,SR,pylsl.cf_double64,"eyelink-" + socket.gethostname()); channels = info.desc().append_child("channels") channels.append_child("channel") \ .append_child_value("label", "leftEyeX") \ .append_child_value("type", "eyetracking") channels.append_child("channel") \ .append_child_value("label", "leftEyeY") \ .append_child_value("type", "eyetracking") channels.append_child("channel") \ .append_child_value("label", "rightEyeX") \ .append_child_value("type", "eyetracking") channels.append_child("channel") \ .append_child_value("label", "rightEyeY") \ .append_child_value("type", "eyetracking")
import sys sys.path.append( '..' ) # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program) import pylsl import random import time # first create a new stream info (here we set the name to MyMarkerStream, the content-type to Markers, 1 channel, irregular sampling rate, and string-valued data) # The last value would be the locally unique identifier for the stream as far as available, e.g. program-scriptname-subjectnumber (you could also omit it but interrupted connections wouldn't auto-recover). # The important part is that the content-type is set to 'Markers', because then other programs will know how to interpret the content info = pylsl.stream_info('MyMarkerStream', 'Markers', 1, 0, pylsl.cf_string, 'dgeyurtutu567sdf') # next make an outlet outlet = pylsl.stream_outlet(info) print("now sending markers...") markernames = ['Test', 'Blah', 'Marker', 'XXX', 'Testtest', 'Test-1-2-3'] while True: # choose a marker string randomly and store it as a pylsl.vectorstr (note that this is actually a list since there can be multiple channels in the sample, even though it is of little use for markers) mysample = pylsl.vectorstr([random.choice(markernames)]) # now send it and wait for a bit outlet.push_sample(mysample) time.sleep(random.random() * 3)
# TEST SCRIPT # NOT FINAL import nidaqmx.system import time import pylsl info = pylsl.stream_info('BioSemi', 'fnir', 1, 100, pylsl.cf_float32, 'myuid34234') #'float32' # next make an outlet outlet = None outlet = pylsl.stream_outlet(info) task = nidaqmx.Task() for num in range(1,17): task.ai_channels.add_ai_voltage_chan('{0}{1}'.format('Dev1/ai',num-1)) print("now sending data...") while True: datarec = task.read(number_of_samples_per_channel=1) #outlet.push_sample(data) stamp = time.time() #100 #local_clock()-0.125 #values=[datarec[1], datarec[2]] outlet.push_sample(pylsl.vectord(datarec[1]), stamp)
import sys sys.path.append( '..' ) # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program) import pylsl import random import time # first create a new stream info (here we set the name to BioSemi, the content-type to EEG, 8 channels, 100 Hz, and float-valued data) # The last value would be the serial number of the device or some other more or less locally unique identifier for the stream as far as available (you could also omit it but interrupted connections wouldn't auto-recover). info = pylsl.stream_info('BioSemi', 'EEG', 8, 100, pylsl.cf_float32, 'dsffwerwer') # next make an outlet outlet = pylsl.stream_outlet(info) print("now sending data...") while True: # make a new random 8-channel sample; this is converted into a pylsl.vectorf (the data type that is expected by push_sample) mysample = pylsl.vectorf([ random.random(), random.random(), random.random(), random.random(), random.random(), random.random(), random.random(), random.random() ]) # now send it and wait for a bit outlet.push_sample(mysample)
try: from emotiv import epoc except ImportError: sys.path.insert(0, "..") from emotiv import epoc if __name__ == "__main__": headset = epoc.EPOC() print "Found headset with serial number: ", headset.serial_number info = pylsl.stream_info( "Emotiv EEG", "EEG", len(headset.channel_mask), headset.sampling_rate, pylsl.cf_int16, str(headset.serial_number), ) info_desc = info.desc() info_desc.append_child_value("manufacturer", "Emotiv") channels = info_desc.append_child("channels") for ch in headset.channel_mask: channels.append_child("channel").append_child_value("label", ch).append_child_value( "unit", "microvolts" ).append_child_value("type", "EEG") # Outgoing buffer size = 360 seconds, transmission chunk size = 32 samples outlet = pylsl.stream_outlet(info, 1, 32)
import pylsl try: from emotiv import epoc except ImportError: sys.path.insert(0, "..") from emotiv import epoc if __name__ == '__main__': headset = epoc.EPOC(method="hidraw") print "Found headset: ", headset.serial_number info = pylsl.stream_info('EPOC', 'EEG', len(headset.channel_mask), headset.sampling_rate, pylsl.cf_int16, str(headset.serial_number)) info_desc = info.desc() info_desc.append_child_value("manufacturer", "Emotiv") channels = info_desc.append_child("channels") for ch in headset.channel_mask: channels.append_child("channel").append_child_value("label", ch).append_child_value("unit","microvolts").append_child_value("type","EEG") # Outgoing buffer size = 360 seconds, transmission chunk size = 32 samples outlet = pylsl.stream_outlet(info, 360, 32) while True: s = headset.get_sample() if s: