simple_LSL_demo_scripted.py PsychoPy Builder app that sends event markers to remote LSL LabRecorder ------------- Intro Routine ------------- Custom Code|Begin Experiment tab -------------------------------- #establish LSL output connection from pylsl import StreamInfo, StreamOutlet try: info = StreamInfo(name="LSL_Markers",type="Markers",channel_count=1,channel_format="int32",source_id="PsychoPyMarker") LSL_outlet = StreamOutlet(info) except: print("Unable to establish LSL outlet for PsychoPy Markers") sys.exit() #open TCP socket connection to remote LSL LabRecorder #used to send operational scripting commands to remote system import socket try: core.wait(2) remoteIP = ('192.168.1.100', 22345) #remote LabRecorder IP addr/port number LSL_socket = socket.create_connection(remoteIP) LSL_socket.sendall(b"filename {root:C:\\LSL\\stream} {template:psycho%n.xdf} {run:99}\n") core.wait(1) LSL_socket.sendall(b"update\n") #Labecorder scan for active LSL streams core.wait(2) LSL_socket.sendall(b"select all\n") #LabRecorder listen to all LSL streams core.wait(1) LSL_socket.sendall(b"start\n") #start LabRecorder except: print("Unable to establish TCP scripting connection to remote LabRecorder") sys.exit() #global variable usd_counter = 1 #synchronous screen flip operation def send_LSL_marker(intMarker): #send intMarker via LSL output stream LSL_outlet.push_sample([intMarker]) ------------- trial Routine ------------- Custom Code|Each Frame Tab -------------------------- #send LSL Marker at stimulus onset if frameN == 0: win.callOnFlip(send_LSL_marker, usd_counter) Custom Code|End Routine Tab --------------------------- #bump stimulus counter usd_counter += 1 Custom Code|End Experiment Tab ------------------------------ #stop remote LSL LabRecorder LSL_socket.sendall(b"stop\n")