How to use the psychopy.iohub.print2err function in psychopy

To help you get started, we’ve selected a few psychopy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github psychopy / psychopy / psychopy / iohub / server.py View on Github external
self.clearEventBuffer()

            try:
                self.closeDataStoreFile()
            except Exception:
                pass

            while len(self.devices) > 0:
                d=self.devices.pop(0)
                try:
                    if d is not None:
                        d._close()
                except Exception:
                        pass
        except Exception:
            print2err("Error in ioSever.shutdown():")
            printExceptionDetailsToStdErr()
github psychopy / psychopy / psychopy / iohub / devices / eyetracker / hw / theeyetribe / pyTribe.py View on Github external
# TODO check status field for any errors
                return True        
        elif msg_category == u'calibration':
            request_type=msg.get('request') 
            #print2err( '::::::::::: Calibration Result: ', msg.get('values',{}).get('calibresult'))            
            if request_type == u'pointend': 
                if msg.get('values',{}).get('calibresult'): 
                    #print2err('::::::::::: Calibration Result: ', msg)                   
                    return self.processCalibrationResult(msg)
            elif request_type == u'pointstart': 
                #print2err( '==========Calibration response: ', msg)
                return True

        print2err('!!!!!!!!!!!!!!!!!!!!!!!!!!')
        print2err('Unhandled Server packet category [{0}] received by client. Full msg contents:\n\n{1}\n<<'.format(msg_category,msg))               
        print2err('!!!!!!!!!!!!!!!!!!!!!!!!!!')
github psychopy / psychopy / psychopy / iohub / server.py View on Github external
filtered_events = []
                for filter in device._filters.values():
                    filtered_events.extend(filter._removeOutputEvents())

                for i in range(len(filtered_events)):
                    e = filtered_events[i]
                    for l in device._getEventListeners(e[DeviceEvent.EVENT_TYPE_ID_INDEX]):
                        l._handleEvent(e)


            except Exception:
                printExceptionDetailsToStdErr()
                print2err("Error in processDeviceEvents: ", device, " : ", len(events), " : ", e)
                print2err("Event type ID: ",e[DeviceEvent.EVENT_TYPE_ID_INDEX], " : " , EventConstants.getName(e[DeviceEvent.EVENT_TYPE_ID_INDEX]))
                print2err("--------------------------------------")
github psychopy / psychopy / psychopy / iohub / launchHubProcess.py View on Github external
glets.append(gevent.spawn(s.processEventsTasklet,0.01))
    
            sys.stdout.write("IOHUB_READY\n\r\n\r")
            sys.stdout.flush()

            #print2err("Computer.psychopy_process: ", Computer.psychopy_process)
            if Computer.psychopy_process:
                 glets.append(gevent.spawn(s.checkForPsychopyProcess, 0.5))

            gevent.joinall(glets)
            

        s.log("Server END Time Offset: {0}".format(Computer.global_clock.getLastResetTime()),'DEBUG')

    except Exception as e:
        print2err("Error occurred during ioServer.start(): ",str(e))
        printExceptionDetailsToStdErr()
        print2err("------------------------------")

        sys.stdout.write("IOHUB_FAILED\n\r\n\r")
        sys.stdout.flush()
        
        try:
            s.shutdown()
        except Exception:
            pass
    
    return -1
github psychopy / psychopy / psychopy / iohub / devices / serial / __init__.py View on Github external
available = []
        if os.name == 'nt':  # Windows
            for i in range(1, 256):
                try:
                    sport = 'COM'+str(i)
                    s = serial.Serial(sport)
                    available.append(sport)
                    s.close()
                except serial.SerialException:
                    pass
        else:  # Mac / Linux
            from serial.tools import list_ports
            available = [port[0] for port in list_ports.comports()]

        if len(available) < 1:
            print2err("Error: unable to find any serial ports on the computer.")
            return []
        return available
github psychopy / psychopy / psychopy / iohub / devices / eyetracker / hw / theeyetribe / pyTribe.py View on Github external
msg_fragment=''
                            self.server_response_count += 1
                        except:
                            msg_fragment=m
            except socket.timeout:
                pass
            except socket.error, e:
                if e.errno==10035 or e.errno==9:
                    pass
                else:
                    print2err( ' socket.error: ',type(e))
                    raise e
            except Exception, e:    
                print2err('>>>>>>>>>>>>')
                print2err('MANAGER ERROR RECEIVING REPLY MSG:',e)
                print2err('reply: ',reply)
                print2err( '<<<<<<<<<<<<')
            finally:
                gevent.sleep(0.001)
        
        # Greenlet has stopped running so close socket.
        self._running=False
        self._socket.close()
github psychopy / psychopy / psychopy / iohub / server.py View on Github external
elif request_type == 'EXP_DEVICE':
            return self.handleExperimentDeviceRequest(request,replyTo)
        elif request_type == 'RPC':
            callable_name=request.pop(0)
            args=None
            kwargs=None
            if len(request)==1:
                args=request.pop(0)
            if len(request)==1:
                kwargs=request.pop(0)    
            
            result=None
            try:
                result=getattr(self,callable_name)
            except Exception:
                print2err("RPC_ATTRIBUTE_ERROR")
                printExceptionDetailsToStdErr()
                self.sendResponse('RPC_ATTRIBUTE_ERROR',replyTo)
                return False
                
            if result and callable(result):
                funcPtr=result
                try:
                    if args is None and kwargs is None:
                        result = funcPtr()
                    elif args and kwargs:
                        result = funcPtr(*args,**kwargs)
                    elif args and not kwargs:
                        result = funcPtr(*args)
                    elif not args and kwargs:
                        result = funcPtr(**kwargs)
                    edata=('RPC_RESULT',callable_name,result)
github psychopy / psychopy / psychopy / iohub / server.py View on Github external
if result and callable(result):
                funcPtr=result
                try:
                    if args is None and kwargs is None:
                        result = funcPtr()
                    elif args and kwargs:
                        result = funcPtr(*args,**kwargs)
                    elif args and not kwargs:
                        result = funcPtr(*args)
                    elif not args and kwargs:
                        result = funcPtr(**kwargs)
                    edata=('RPC_RESULT',callable_name,result)
                    self.sendResponse(edata,replyTo)
                    return True
                except Exception,e:
                    print2err("RPC_RUNTIME_ERROR")
                    printExceptionDetailsToStdErr()
                    self.sendResponse('RPC_RUNTIME_ERROR', replyTo)
                    return False
            else:
                print2err("RPC_NOT_CALLABLE_ERROR")
                printExceptionDetailsToStdErr()
                self.sendResponse('RPC_NOT_CALLABLE_ERROR', replyTo)
                return False
        elif request_type == 'STOP_IOHUB_SERVER':
            try:
                self.shutDown()
            except Exception:
                printExceptionDetailsToStdErr
        else:
            print2err("RPC_NOT_CALLABLE_ERROR")
            printExceptionDetailsToStdErr()
github psychopy / psychopy / psychopy / iohub / devices / eyetracker / hw / tobii / eyetracker.py View on Github external
the eye tracker device, and the local ioHub time the callback was
        called, into a buffer for processing by the ioHub event system.
        """
        if self.isReportingEvents():
            try:
                if self._isEyeX:
                    eye_data_event=args[0]
                    return self._handleNativeEyeXEvent(eye_data_event)
                else:
                    eye_data_event=args[1]
                    return self._handleNativeTobiiEvent(eye_data_event)
            except Exception:
                print2err("ERROR IN _handleNativeEvent")
                printExceptionDetailsToStdErr()
        else:
            print2err("self._handleNativeEvent called but isReportingEvents == false")
github psychopy / psychopy / psychopy / iohub / devices / eyetracker / hw / gazepoint / gp3 / eyetracker.py View on Github external
else:
                    print2err('***** GP3 Closed Connection *****')
                    # Connection closed
                    self.setRecordingState(False)
                    self.setConnectionState(False)
                    self._rx_buffer=''
                    return None

            except socket.error, e:
                err = e.args[0]
                if err == errno.EAGAIN or err == errno.EWOULDBLOCK or err == 'timed out':
                    # non blocking socket found no data; it happens.
                    return self._rx_buffer
                else:
                    # a valid error occurred
                    print2err('***** _checkForNetData Error *****')
                    printExceptionDetailsToStdErr()
                    return self._rx_buffer