Пример #1
0
def quickStartHubServer(experimentCode, sessionCode, **deviceConfigs):
    from ioHub.client import ioHubConnection

    devices=deviceConfigs
    
    if len(devices)==0:
        # Specify devices you want to use in the ioHub
        devices=OrderedDict()
        devices['Display']={'origin':'center','reporting_unit_type':'pix'}
        devices['Keyboard']={}
        devices['Mouse']={}
    # Create an ioHub configuration dictionary.
    ioConfig=dict(monitor_devices=devices)
    
    if experimentCode and sessionCode:    
        # Enable saving of all keyboard and mouse events to the 'ioDataStore'
        ioConfig['data_store']=dict(experiment_info=dict(code=experimentCode),session_info=dict(code=sessionCode))
    
    # Start the ioHub Server
    return ioHubConnection(ioConfig)
Пример #2
0
    def _initalizeConfiguration(self):
        global _currentSessionInfo
        """
        Based on the configuration data in the experiment_config.yaml and iohub_config.yaml,
        configure the experiment environment and ioHub process environments. This mehtod is called by the class init
        and should not be called directly.
        """
        display_experiment_dialog=self.configuration.get("display_experiment_dialog",False)
        display_session_dialog=self.configuration.get("display_session_dialog",True)
        
        
        if display_experiment_dialog is True:        
            # display a read only dialog verifying the experiment parameters
            # (based on the experiment .yaml file) to be run. User can hit OK to continue,
            # or Cancel to end the experiment session if the wrong experiment was started.
            exitExperiment=self._displayExperimentSettingsDialog()
            if exitExperiment:
                print "User Cancelled Experiment Launch."
                self._close()
                sys.exit(1)

        self.experimentConfig=self.prePostExperimentVariableCallback(self.experimentConfig)

        ioHubInfo= self.configuration.get('ioHub',{})
        
        if ioHubInfo is None:
            print 'ioHub section of configuration file could not be found. Exiting.....'
            self._close()
            sys.exit(1)
        else:
            from ioHub.client import ioHubConnection

            ioHubConfigFileName=unicode(ioHubInfo.get('config','iohub_config.yaml'))
            ioHubConfigAbsPath=os.path.join(self.configFilePath,unicode(ioHubConfigFileName))
            self.hub=ioHubConnection(None,ioHubConfigAbsPath)

            #print 'ioHubExperimentRuntime.hub: {0}'.format(self.hub)
            # A circular buffer used to hold events retrieved from self.getEvents() during
            # self.delay() calls. self.getEvents() appends any events in the allEvents
            # buffer to the result of the hub.getEvents() call that is made.
            self.hub.allEvents=deque(maxlen=self.configuration.get('event_buffer_length',256))

            #print 'ioHubExperimentRuntime sending experiment config.....'
            # send experiment info and set exp. id
            self.hub._sendExperimentInfo(self.experimentConfig)

            #print 'ioHubExperimentRuntime SENT experiment config.'
           
            allSessionDialogVariables = dict(self.experimentSessionDefaults, **self.sessionUserVariables)
            sessionVariableOrder=self.configuration['session_variable_order']
            if 'user_variables' in allSessionDialogVariables:
                del allSessionDialogVariables['user_variables']
    
            if display_session_dialog is True:
                # display session dialog
                r=True
                while r is True:
                    # display editable session variable dialog displaying the ioHub required session variables
                    # and any user defined session variables (as specified in the experiment config .yaml file)
                    # User can enter correct values and hit OK to continue, or Cancel to end the experiment session.
    
                    allSessionDialogVariables = dict(self.experimentSessionDefaults, **self.sessionUserVariables)
                    sessionVariableOrder=self.configuration['session_variable_order']
                    if 'user_variables' in allSessionDialogVariables:
                        del allSessionDialogVariables['user_variables']
         
                    tempdict=self._displayExperimentSessionSettingsDialog(allSessionDialogVariables,sessionVariableOrder)
                    if tempdict is None:
                        print "User Cancelled Experiment Launch."
                        self._close()
                        sys.exit(1)
                
                    tempdict['user_variables']=self.sessionUserVariables
    
                    r=self.isSessionCodeNotInUse(tempdict['code'])
                     
                    if r is True:
                        display_device=self.hub.getDevice('display')
                        display_id=0
                        if display_device:
                            display_id=display_device.getIndex()
                        msg_dialog=ioHub.util.experiment.dialogs.MessageDialog(
                                        "Session Code {0} is already in use by the experiment.\nPlease enter a new Session Code".format(tempdict['code']),
                                        "Session Code In Use",
                                        dialogType=ioHub.util.experiment.dialogs.MessageDialog.ERROR_DIALOG,
                                        allowCancel=False,
                                        display_index=display_id)
                        msg_dialog.show()
            else:
                tempdict=allSessionDialogVariables
                tempdict['user_variables']=self.sessionUserVariables

            for key,value in allSessionDialogVariables.iteritems():
                if key in self.experimentSessionDefaults:
                    self.experimentSessionDefaults[key]=value#(u''+value).encode('utf-8')
                elif  key in self.sessionUserVariables:
                    self.sessionUserVariables[key]=value#(u''+value).encode('utf-8')      


            tempdict=self.prePostSessionVariableCallback(tempdict)
            tempdict['user_variables']=self.sessionUserVariables

            _currentSessionInfo=self.experimentSessionDefaults

            self.hub._sendSessionInfo(tempdict)

            # create necessary paths based on yaml settings,
            self.paths=PathMapping(self.configFilePath,self.configuration.get('paths',None))
    
            self.paths.saveToJson()
        

            self._setInitialProcessAffinities(ioHubInfo)

            return self.hub