def stop(self): """cose file and stop tracking""" self.el.sendMessage("END") pl.endRealTimeMode() pl.getEYELINK().setOfflineMode() # el.sendCommand("set_offline_mode = YES") self.el.closeDataFile()
def End_trial(self): pylink.endRealTimeMode() # Fin mode temps réel pylink.pumpDelay( 100) # ajout 100ms de donnée pour les évenement finaux self.eyelink.stopRecording() while self.eyelink.getkey(): pass
def endTrial(self): '''Ends recording: adds 100 msec of data to catch final events''' pylink.endRealTimeMode() pylink.pumpDelay(100) self.tracker.stopRecording() while self.tracker.getkey(): pass
def endTrial(self): '''Ends recording: adds 100 msec of data to catch final events''' pylink.endRealTimeMode() pylink.pumpDelay(100) self.tracker.stopRecording() while self.tracker.getkey() : pass;
def endTrial(self): '''Ends recording: adds 100 msec of data to catch final events''' pylink.endRealTimeMode( ) #Returns the application to a priority slightly above normal, to end realtime mode pylink.pumpDelay(100) # ??????? self.tracker.stopRecording( ) #Stops recording, resets EyeLink data mode. Call 50 to 100 msec after an event occurs that ends the trial.
def stop_recording(self): """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker""" self.recording = False pylink.endRealTimeMode() pylink.getEYELINK().setOfflineMode() pylink.msecDelay(500)
def postTrial(self): '''Ends recording: adds 100 msec of data to catch final events''' self.tracker.sendMessage("POSTTRIAL") pylink.endRealTimeMode() pylink.pumpDelay(100) self.tracker.stopRecording() while self.tracker.getkey() : pass;
def stopRecording(): """Stop eyetracker recording """ if getExperiment().recording: pylink.endRealTimeMode() pylink.msecDelay(100) getTracker().stopRecording() getExperiment().recording = False
def end_trial(): '''Ends recording: adds 100 msec of data to catch final events''' MySurface.fill((0,0,0)) ## should clear the screen!!!!!!!!!!! pylink.endRealTimeMode(); pylink.pumpDelay(100); MyEyelink.stopRecording(); while MyEyelink.getkey() : pass;
def fin_enregistrement(self): #eyelink.sendMessage("TRIAL_RESULT %d" % button) ret_value = self.eyelink.getRecordingStatus( ) # état de l'enregistrement de sortie self.End_trial() #gc.enable() # Réactivez la collecte python pour nettoyer la mémoire à la fin de l'essai pylink.endRealTimeMode() return ret_value
def run_trials(MyEnv, start, break_interval): ''' This function is used to run individual trials and handles the trial return values. ''' ''' Returns a successful trial with 0, aborting experiment with ABORT_EXPT (3); It also handles the case of re-running a trial. ''' global MySurface, MyMonitor, MyEyelink, MyTable, MyInfo, FPS_CONTROL MySurface, MyMonitor, MyEyelink, MyTable, MyInfo = MyEnv.getDetails() # Give the screen reference to Stimuli, and initialize them: FPS_CONTROL = MyMonitor.fps_control # Give the screen reference to Stimuli, and initialize them: initStimuliO(MyEnv) utils.displayInstruction(MyEnv, "instructions-same.txt") #Do the tracker setup at the beginning of the experiment. if MyEyelink.getTrackerVersion() == -1: global dummy dummy = True utils.displayTestScreen(MyEnv, 13., 16) # display test screen in dummy mode; nb_trials = len(MyTable[start:,0]) for i, trial in enumerate(MyTable[start:,:]): ## read the parameter's table line-by-line from the start number if(MyEyelink.isConnected() ==0 or MyEyelink.breakPressed()): break; if i % break_interval == 0 and i>0: s = "Part %d on %d achieved !"%(i / break_interval, nb_trials/break_interval ) event = utils.displayInstruction(MyEnv, "waiting_message.txt", additional_text = s) if event.key == pygame.K_r: event = utils.runCalibration(MyEnv) if event.key == pygame.K_ESCAPE: MyEyelink.sendMessage("EXPERIMENT ABORTED") return pylink.ABORT_EXPT, FRAME_INTERVALS; while 1: ret_value = do_trial(trial) pylink.endRealTimeMode() if (ret_value == pylink.TRIAL_OK): MyEyelink.sendMessage("TRIAL OK"); break; elif (ret_value == pylink.SKIP_TRIAL): MyEyelink.sendMessage("TRIAL %s SKIPPED"%str(i)); print "TRIAL %s SKIPPED"%str(i) break; elif (ret_value == pylink.ABORT_EXPT): MyEyelink.sendMessage("EXP. ABORTED AT TRIAL %s"%str(i)); print "EXP. ABORTED AT TRIAL %s"%str(i) return pylink.ABORT_EXPT, FRAME_INTERVALS; elif (ret_value == pylink.REPEAT_TRIAL): utils.runCalibration(MyEnv) MyEyelink.sendMessage("TRIAL REPEATED after Calibration"); else: MyEyelink.sendMessage("TRIAL ERROR") break; return 0, FRAME_INTERVALS;
def stop_recording(self): """ Stop recording of gaze samples """ self.recording = False pylink.endRealTimeMode() pylink.getEYELINK().setOfflineMode() pylink.msecDelay(500)
def stop_recording(self): """<DOC> Stops recording of gaze samples. </DOC>""" self.recording = False pylink.endRealTimeMode() pylink.getEYELINK().setOfflineMode() pylink.msecDelay(500)
def stop_recording(self): '''Ends recording: adds 100 msec of data to catch final events''' pylink.endRealTimeMode() pylink.pumpDelay(100) self.tracker.stopRecording() # self.display_message('Recording stopped.') while self.tracker.getkey(): pass
def record(self, *args, **keywords): """Runs the trial displays while communicating with the eyetracker. TO-DO: currently contains a hack for stopping audio when trial is aborted. This needs to be done in a more general and implementation-independent way. """ while 1: getTracker().flushKeybuttons(1) Trial.trialNumber += 1 getLog().push() getLog().logAttributes(trialNumber=Trial.trialNumber) getLog().logAttributes(getattr(self, 'metadata', {})) getTracker().sendMessage('TRIALID %s' % (Trial.trialNumber)) getTracker().drawText("Trial_%s\n" % (Trial.trialNumber), pos=(1, 20)) getTracker().sendCommand("record_status_message 'TRIALID %s'" % (Trial.trialNumber)) self.sendDataViewerBG() self.sendRTperiod() try: result = self.run(*args, **keywords) except TrialAbort, abort: for rc in getExperiment().response_collectors: rc.stop() # HACK!!! # Need to find a good implementation-independent way of ensuring that sound streams get stopped. pygame.mixer.stop() getExperiment().recording = False pylink.endRealTimeMode() getLog().logAttributes(trial_abort=abort.abortAction) for key, value in getLog().currentData().iteritems(): setTrialVar(key, value) pygame.time.delay(1) getLog().pop() getTracker().sendMessage('TRIAL_RESULT %d' % (abort.abortAction)) if abort.abortAction == pylink.REPEAT_TRIAL: pass elif abort.abortAction == pylink.TRIAL_ERROR: calibrateTracker() elif abort.abortAction == pylink.SKIP_TRIAL: return None else: raise else: getLog().logAttributes(trial_abort=0) for key, value in getLog().currentData().iteritems(): setTrialVar(key, value) pygame.time.delay(1) getLog().pop() getTracker().sendMessage('TRIAL_RESULT 0') return result
def stop_recording(self): """ Stop recording of gaze samples """ self.recording = False pylink.endRealTimeMode(); pylink.getEYELINK().setOfflineMode(); pylink.msecDelay(500);
def stop(self): ''' Docstring Parameters ---------- Returns ------- ''' self.tracker.stopRecording() pylink.endRealTimeMode()
def record(self,*args,**keywords): """Runs the trial displays while communicating with the eyetracker. TO-DO: currently contains a hack for stopping audio when trial is aborted. This needs to be done in a more general and implementation-independent way. """ while 1: getTracker().flushKeybuttons(1) Trial.trialNumber += 1 getLog().push() getLog().logAttributes(trialNumber=Trial.trialNumber) getLog().logAttributes(getattr(self,'metadata',{})) getTracker().sendMessage('TRIALID %s'%(Trial.trialNumber)) getTracker().drawText("Trial_%s\n"%(Trial.trialNumber),pos=(1,20)) getTracker().sendCommand("record_status_message 'TRIALID %s'"%(Trial.trialNumber)) self.sendDataViewerBG() self.sendRTperiod() try: result = self.run(*args,**keywords) except TrialAbort,abort: for rc in getExperiment().response_collectors: rc.stop() # HACK!!! # Need to find a good implementation-independent way of ensuring that sound streams get stopped. pygame.mixer.stop() getExperiment().recording = False pylink.endRealTimeMode() getLog().logAttributes(trial_abort=abort.abortAction) for key,value in getLog().currentData().iteritems(): setTrialVar(key,value) pygame.time.delay(1) getLog().pop() getTracker().sendMessage('TRIAL_RESULT %d'%(abort.abortAction)) if abort.abortAction == pylink.REPEAT_TRIAL: pass elif abort.abortAction == pylink.TRIAL_ERROR: calibrateTracker() elif abort.abortAction == pylink.SKIP_TRIAL: return None else: raise else: getLog().logAttributes(trial_abort=0) for key,value in getLog().currentData().iteritems(): setTrialVar(key,value) pygame.time.delay(1) getLog().pop() getTracker().sendMessage('TRIAL_RESULT 0') return result
def stop(self): """Stops recording data from the eye tracker. Called automatically at the end of each trial unless ``P.manual_eyelink_recording`` is True, in which case it must be called manually in order to stop recording at any point. To resume recording after this method is called, use the :meth:`start` method. """ endRealTimeMode() pumpDelay(100) self.stopRecording() self.__recording = False self.sendMessage("TRIAL OK") flushGetkeyQueue()
def CoolDown(): # Save behavioral data thisExp.nextEntry() # advance data file thisExp.saveAsWideText(filename + '.csv') # stop recording eye data pylink.endRealTimeMode() pylink.pumpDelay(100) error = tk.stopRecording() # Clear the screen win.flip() # display cool-down message message1.setText("That's the end! ") message2.setText("Press 'q' or 'escape' to end the run.") win.logOnFlip(level=logging.EXP, msg='Display TheEnd') message1.draw() message2.draw() win.flip() # Wait for keypress thisKey = event.waitKeys(keyList=['q','escape']) # --- EyeLink code --- # # close the EDF data file tk.setOfflineMode() tk.closeDataFile() pylink.pumpDelay(50) # Get the EDF data and say goodbye message1.text='Data transfering.....' message1.draw() win.flip() tk.receiveDataFile(dataFileName, dataFolder + dataFileName) #close the link to the tracker tk.close() # close the graphics pylink.closeGraphics() # --- End EyeLink code --- # # exit win.close() core.quit()
def startRecording(): """Commence eyetracker recording and verify that it's working. """ getTracker().resetData() getTracker().startRecording(1,1,1,1) getExperiment().recording = True pylink.beginRealTimeMode(100) try: if not getTracker().waitForBlockStart(1000,1,1): raise Exception("waitForBlockStart failed") except Exception: getTracker().drawText("LINK DATA NOT RECEIVED!",pos=(1,20)) pylink.endRealTimeMode() pylink.msecDelay(2000) getTracker().stopRecording() print "LINK DATA NOT RECEIVED!" raise TrialAbort(pylink.TRIAL_ERROR)
def startRecording(): """Commence eyetracker recording and verify that it's working. """ getTracker().resetData() getTracker().startRecording(1, 1, 1, 1) getExperiment().recording = True pylink.beginRealTimeMode(100) try: if not getTracker().waitForBlockStart(1000, 1, 1): raise Exception("waitForBlockStart failed") except Exception: getTracker().drawText("LINK DATA NOT RECEIVED!", pos=(1, 20)) pylink.endRealTimeMode() pylink.msecDelay(2000) getTracker().stopRecording() print "LINK DATA NOT RECEIVED!" raise TrialAbort(pylink.TRIAL_ERROR)
def do_trial(par): '''Does the simple trial''' id_number = str(par[0])+" TRIAL_TYPE "+str(par[1])+" CODE_TYPE "+str(par[-1]) ## par contains the trial parameters ##This supplies the title at the bottom of the eyetracker display # message ="record_status_message 'Trial %s'"%id_number # MyEyelink.sendCommand(message); ##Always send a TRIALID message before starting to record. ##EyeLink Data Viewer defines the start of a trial by the TRIALID message. ##This message is different than the start of recording message START that is logged when the trial recording begins. ##The Data viewer will not parse any messages, events, or samples, that exist in the data file prior to this message. msg = "TRIALID %s"%id_number; MyEyelink.sendMessage(msg); ##This TRIAL_VAR command specifies a trial variable and value for the given trial. ##Send one message for each pair of trial condition variable and its corresponding value. ## You can put this in a function updateStimuliFromParameters(par) #giveParametersToEyeTracker(par) ## you can do a drifcorrection if you want ## fonction() error = MyEyelink.startRecording(1,1,1,1) if error: return error; gc.disable(); # switch off the garbage collector #begin the realtime mode pylink.beginRealTimeMode(100) if not MyEyelink.waitForBlockStart(100, 1, 0): end_trial(); print "ERROR: No link samples received!"; return pylink.TRIAL_ERROR; ## we inserted the gap duration information at par[-4] and the type_code at par[-1] ## the fixation duration if now at par[-5] ## the gap duration is used by drawCondition ## (change from previous program: par[-3:] to par[-5:-1]) ret_value = drawCondition(*par[-5:-1].astype(int)); pylink.endRealTimeMode(); gc.enable(); return ret_value;
def EyelinkStop(Name, el=pylink.getEYELINK()): """ Performs stopping routines for the EyeLink 1000 Plus eyetracker. **Author** : Wanja Mössing, WWU Münster | [email protected] \n *July 2017* Parameters: ----------- Name : string filename of the edf. Doesn't have to, but can, end on '.edf' Must be the same name used during EyelinkStart() el : Eyelink Object Eyelink object returned by EyelinkStart(). By default this function tried to find it itself. """ # Check filename if '.edf' not in Name.lower(): Name += '.edf' # stop realtime mode pylink.endRealTimeMode() # make sure all experimental procedures finished pylink.msecDelay(1000) # stop the recording el.stopRecording() # put Eyelink back to idle el.setOfflineMode() # wait for stuff to finish pylink.msecDelay(500) # close edf el.closeDataFile() # transfer edf to display-computer try: print('Wait for EDF to be copied over LAN...') if not path.exists('./EDF'): mkdir('./EDF') el.receiveDataFile(Name, './EDF/'+Name) print('Done. EDF has been copied to ./EDF folder.') except RuntimeError: print('Error while pulling EDF file. Try to find it on Eyelink host..') el.close() pylink.closeGraphics() return
def EyelinkStop(Name, el=pylink.getEYELINK()): """ Performs stopping routines for the EyeLink 1000 Plus eyetracker. **Author** : Wanja Mössing, WWU Münster | [email protected] \n *July 2017* Parameters: ----------- Name : string filename of the edf. Doesn't have to, but can, end on '.edf' Must be the same name used during EyelinkStart() el : Eyelink Object Eyelink object returned by EyelinkStart(). By default this function tried to find it itself. """ # Check filename if '.edf' not in Name.lower(): Name += '.edf' # stop realtime mode pylink.endRealTimeMode(0) # make sure all experimental procedures finished pylink.msecDelay(1000) # stop the recording el.stopRecording() # put Eyelink back to idle el.setOfflineMode() # wait for stuff to finish pylink.msecDelay(500) # close edf el.closeDataFile() # transfer edf to display-computer try: print('Wait for EDF to be copied over LAN...') if not path.exists('./EDF'): mkdir('./EDF') el.receiveDataFile(Name, './EDF/' + Name) print('Done. EDF has been copied to ./EDF folder.') except RuntimeError: print('Error while pulling EDF file. Try to find it on Eyelink host..') el.close() pylink.closeGraphics() return
def runTrial(params, expInfo): """ pars should be a list, like ['red', 'red', 'left', 'cong'] dataFile is an opened csv file that use to store our data in a sheet. """ # unpacking the parameters text, textColor, correctAnswer, congruency = params # prepare the stimuli word = visual.TextStim(win=win, text=text, font='Arial', height=100.0, color=textColor) w, h = word.boundingBox # flush cached button presses (eyelink) tk.flushKeybuttons(0) tk.setOfflineMode() pylink.msecDelay(50) # OPTIONAL-- draw the text on the Host screen and show the bounding box tk.sendCommand('clear_screen 0') # clear the host Display first tk.sendCommand('draw_text %d %d 6 %s' % (scnWidth / 2, scnHeight / 2, text)) tk.sendCommand('draw_box %d %d %d %d 6' % (scnWidth / 2 - w / 2, scnHeight / 2 - h / 2, scnWidth / 2 + w / 2, scnHeight / 2 + h / 2)) # log trial onset message tk.sendMessage("TRIALID %s %s %s" % (text, textColor, congruency)) # record_status_message : show some info on the host PC tk.sendCommand("record_status_message 'congruency: %s'" % congruency) #Optional - start realtime mode pylink.beginRealTimeMode(100) # do driftcheck try: error = tk.doDriftCorrect(scnWidth / 2, scnHeight / 2, 1, 1) except: tk.doTrackerSetup() # start recording, parameters specify whether events and samples are # stored in file, and available over the link tk.startRecording(1, 1, 1, 1) pylink.msecDelay(50) # Clear bufferred events (in Psychopy) event.clearEvents(eventType='keyboard') # draw the target word on display word.draw() win.flip() tk.sendMessage("SYNCTIME") # message to mark the onset of visual stimuli # save a screenshot so we can use it in Data Viewer to superimpose the gaze if not os.path.exists('screenshotFolder'): os.mkdir('screenshotFolder') screenshot = 'screenshotFolder' + os.sep + 'cond_%s_%s.jpg' % (text, textColor) win.getMovieFrame() win.saveMovieFrames(screenshot) # send a Data Viewer integration message here, so DV knows which screenshot to load tk.sendMessage('!V IMGLOAD FILL %s' % ('..' + os.sep + screenshot)) # check for response & time out gotKey = False timeOut = False tStart = core.getTime() subjResp = ['None', 'None'] while not (gotKey or timeOut): # check for time out tNow = core.getTime() if tNow - tStart >= 10.0: timeOut = True # check for key presses keyPressed = event.getKeys(['left', 'right', 'down', 'escape']) if len(keyPressed) > 0: if 'escape' in keyPressed: tk.sendMessage("Quit") win.close() core.quit() # terminate the task if ESCAPE is pressed else: subjResp = [keyPressed[0], tNow] tk.sendMessage("RESPONSE %s" % (keyPressed[0])) gotKey = True # clear the subject display win.color = 'black' win.flip() # clear the host Display tk.sendCommand('clear_screen 0') # was the subject's response 'correct'? if subjResp[0] == correctAnswer: respAcc = 1 else: respAcc = 0 # OPTIONAL-- set an Interest Area for data viewer integraiton # a full list of Data Viewer integration messages and their syntax can be found in the Data Viewer Manual # (Help menu -> Contents -> Protocol for EyeLink Data To Viewer Integraiton). tk.sendMessage("!V IAREA RECTANGLE 1 %d %d %d %d target" % (scnWidth / 2 - w / 2, scnHeight / 2 - h / 2, scnWidth / 2 + w / 2, scnHeight / 2 + h / 2)) # EyeLink - Send Trialvar messages for data viewer integraiton # a full list of Data Viewer integration messages and their syntax can be found in the Data Viewer Manual # (Help menu -> Contents -> Protocol for EyeLink Data To Viewer Integraiton). tk.sendMessage("!V TRIAL_VAR word %s" % (text)) tk.sendMessage("!V TRIAL_VAR color %s" % (textColor)) tk.sendMessage("!V TRIAL_VAR congruency %s" % (congruency)) tk.sendMessage("!V TRIAL_VAR respAcc %d" % (respAcc)) # Optional-- end realtime mode pylink.endRealTimeMode() pylink.msecDelay(100) # send a message to mark the end of trial tk.sendMessage("TRIAL_RESULT %d" % (respAcc)) pylink.msecDelay(100) # EyeLink - stop recording eye data tk.stopRecording() pylink.msecDelay(50) tk.setOfflineMode()
win.flip() else: # this Routine was not non-slip safe so reset non-slip timer routineTimer.reset() #-------Ending Routine "trial"------- for thisComponent in trialComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # thisExp.nextEntry() # trialsFilePath = filePath + os.sep + fileName + '_trials' # trials.saveAsPickle(trialsFilePath) # trials.saveAsText(trialsFilePath) # print trials # File transfer and cleanup! pl.endRealTimeMode() el.setOfflineMode() pl.msecDelay(600) #Close the file and transfer it to Display PC el.closeDataFile() el.receiveDataFile(edfFileName, edfFileName) el.close() print "finished the experiment" win.close() core.quit()
pylink.getEYELINK().sendCommand( "file_sample_data = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS,HTARGET") else: pylink.getEYELINK().sendCommand( "file_sample_data = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS") pylink.setCalibrationColors((0, 0, 0), (255, 255, 255)) #Sets the calibration target and background color pylink.setTargetSize(int(window_size[0] / 40), int(window_size[0] / 30)) #select best size for calibration target pylink.beginRealTimeMode(0) print('started real time mode') pylink.getEYELINK().startRecording(1, 1, 0, 0) core.wait(3) pylink.endRealTimeMode() pylink.getEYELINK().setOfflineMode() win.close() if pylink.getEYELINK() != None: # File transfer and cleanup! pylink.getEYELINK().setOfflineMode() pylink.msecDelay(500) #Close the file and transfer it to Display PC pylink.getEYELINK().closeDataFile() pylink.getEYELINK().receiveDataFile(edf_filename, edf_filename) pylink.getEYELINK().close()
def elEndRec(el): # Ends the recording; adds 100ms to catch final events pl.endRealTimeMode() pl.pumpDelay(100) el.stopRecording()
def stopEyeTracking(self): #Ends recording: adds 100 msec of data to catch final events pylink.endRealTimeMode() pylink.pumpDelay(100) self.tracker.stopRecording()
core.quit() # refresh the screen # don't flip if this routine is over or we'll get a blank screen if continueRoutine: win.flip() else: # this Routine was not non-slip safe so reset non-slip timer routineTimer.reset() #-------Ending Routine "trial"------- for thisComponent in trialComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) if et: # File transfer and cleanup! pl.endRealTimeMode() el.setOfflineMode() pl.msecDelay(600) #Close the file and transfer it to Display PC el.closeDataFile() el.receiveDataFile(edfFileName, edfFileName) os.rename(edfFileName, filePath + os.sep + edfFileName) el.close() print "finished the experiment" win.close() core.quit()
pylink.getEYELINK().sendCommand("file_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON") if tracker_software_ver>=4: pylink.getEYELINK().sendCommand("file_sample_data = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS,HTARGET") else: pylink.getEYELINK().sendCommand("file_sample_data = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS") pylink.setCalibrationColors( (0, 0, 0),(255, 255, 255)); #Sets the calibration target and background color pylink.setTargetSize(int(window_size[0]/40), int(window_size[0]/30)); #select best size for calibration target #----------------------------------------------------------------------------- pylink.beginRealTimeMode(0) print 'started real time mode' pylink.getEYELINK().startRecording(1, 1, 0, 0) core.wait(3) pylink.endRealTimeMode() pylink.getEYELINK().setOfflineMode() win.close() if pylink.getEYELINK() != None: # File transfer and cleanup! pylink.getEYELINK().setOfflineMode(); pylink.msecDelay(500); #Close the file and transfer it to Display PC pylink.getEYELINK().closeDataFile() pylink.getEYELINK().receiveDataFile(globvar.edf_filename, globvar.edf_filename) pylink.getEYELINK().close();