コード例 #1
0
    def __init__(self, host, port, default_package_size=1024, connect=True):
        """Create a TcpClient.

        Parameters:
        -----------
        host : str
            The hostname or IPv4 address of the server to connect to.
        port : int
            The port to connect to.
        default_package_size : int, optional
            The default size of the packages to be received (default=1024).
        connect : bool, optional
            If True, connect immediately (default=True).

        """

        Input.__init__(self)
        Output.__init__(self)

        self._host = host
        self._port = port
        self._default_package_size = default_package_size
        self._socket = None
        self._is_connected = False
        if connect:
            self.connect()
コード例 #2
0
    def __init__(self, device, buffer_size=None):
        """Create a MIDI input.

        Parameters
        ----------
        device : int or str
            id or name of the MIDI device
        buffer_size : int, optional
            number of events to be buffered

        """

        import types
        if type(_midi) is not types.ModuleType:
            raise ImportError("""Sorry, MIDI input is not supported on this computer.""")

        if not expyriment._active_exp.is_initialized:
            raise RuntimeError(
                "Cannot create MidiIn before expyriment.initialize()!")
        _midi.init()
        Input.__init__(self)
        self._id = device
        if buffer_size is None:
            buffer_size = defaults.midiin_buffer_size
        self._buffer_size = buffer_size
        self.input = _midi.Input(device, buffer_size)
コード例 #3
0
    def __init__(self, port, default_package_size=None, start_listening=True):
        """Create a TcpServer.

        Parameters:
        -----------
        port : int
            The port to connect to.
        default_package_size : int, optional
            The default size of the packages to be received.
        start_listening : bool
            If True, start listening on port immediately.

        """

        Input.__init__(self)
        Output.__init__(self)

        self._port = port
        if default_package_size is None:
            default_package_size = defaults.tcpserver_default_package_size
        self._default_package_size = default_package_size
        self._socket = None
        self._is_connected = False
        if start_listening is None:
            start_listening = defaults.tcpserver_start_listening
        if start_listening:
            self.listen()
コード例 #4
0
    def __init__(self, host, port, timeout=2000, connect=True):
        """Create a TurbosatoriNetworkInterface.

        Parameters:
        -----------
        host : str
            The hostname or IPv4 address of the TBV server to connect to.
        port : int
            The port on the Turbo-Satori server to connect to.
        timeout : int, optional
            The maximal time to wait for a response from the server for each
            request (default=2000).
        connect : bool, optional
            If True, connect immediately (default=True).

        """

        Input.__init__(self)
        Output.__init__(self)

        self._host = host
        self._port = port
        self._is_connected = False
        self._turbosatori_plugin_version = None
        self._tcp = TcpClient(host, port, None, False)
        self._timeout = timeout
        if connect:
            self.connect()
コード例 #5
0
    def __init__(self, host, port, default_package_size=None, connect=None):
        """Create a TcpClient and connect to it.

        Parameters:
        -----------
        host : str
            The hostname or IPv4 address of the server to connect to.
        port : int
            The port to connect to.
        default_package_size : int
            The default size of the packages to be received.
        connect : bool, optional
            If True, connect immediately.

        """

        Input.__init__(self)
        Output.__init__(self)

        self._host = host
        self._port = port
        if default_package_size is None:
            default_package_size = defaults.tcpclient_default_package_size
        self._default_package_size = default_package_size
        self._socket = None
        self._is_connected = False
        if connect is None:
            connect = defaults.tcpclient_connect
        if connect:
            self.connect()
コード例 #6
0
    def __init__(self, port=0):
        """Create a parallel port input and output.

        Parameters:
        -----------
        port : int, optional
            The port to use (default=0).

        """

        if not isinstance(parallel, ModuleType):
            message = """SimpleParallelPort can not be initialized.
The Python package 'pyParallel' is not installed."""
            raise ImportError(message)

        if float(parallel.VERSION) < 0.2:
            raise ImportError("Expyriment {0} ".format(__version__) +
                              "is not compatible with PyParallel {0}.".format(
                                  parallel.VERSION) +
                              "\nPlease install PyParallel 0.2 or higher.")

        Input.__init__(self)
        Output.__init__(self)
        self._port = port
        self._parallel = parallel.Parallel(self._port)
        self.input_history = False  # dummy
コード例 #7
0
    def __init__(self, host, port, timeout=2000, connect=True):
        """Create a TurbosatoriNetworkInterface.

        Parameters:
        -----------
        host : str
            The hostname or IPv4 address of the TBV server to connect to.
        port : int
            The port on the Turbo-Satori server to connect to.
        timeout : int, optional
            The maximal time to wait for a response from the server for each
            request (default=2000).
        connect : bool, optional
            If True, connect immediately (default=True).

        """

        Input.__init__(self)
        Output.__init__(self)

        self._host = host
        self._port = port
        self._is_connected = False
        self._turbosatori_plugin_version = None
        self._tcp = TcpClient(host, port, None, False)
        self._timeout = timeout
        if connect:
            self.connect()
コード例 #8
0
    def __init__(self, port=0):
        """Create a parallel port input and output.

        Parameters:
        -----------
        port : int, optional
            The port to use (default=0).

        """

        if not isinstance(parallel, ModuleType):
            message = """SimpleParallelPort can not be initialized.
The Python package 'pyParallel' is not installed."""
            raise ImportError(message)

        if float(parallel.VERSION) < 0.2:
            raise ImportError("Expyriment {0} ".format(__version__) +
                    "is not compatible with PyParallel {0}.".format(
                        parallel.VERSION) +
                      "\nPlease install PyParallel 0.2 or higher.")

        Input.__init__(self)
        Output.__init__(self)
        self._port = port
        self._parallel = parallel.Parallel(self._port)
        self.input_history = False # dummy
コード例 #9
0
    def __init__(self, host, port, timeout=None, connect=None):
        """Create a TbvNetworkInterface.

        Parameters:
        -----------
        host : str
            The hostname or IPv4 address of the TBV server to connect to.
        port : int
            The port on the TBV server to connect to.
        timeout : int, optional
            The maximal time to wait for a response from the server for each
            request.
        connect : bool, optional
            If True, connect immediately.

        """

        Input.__init__(self)
        Output.__init__(self)

        self._host = host
        self._port = port
        self._is_connected = False
        self._tbv_plugin_version = None
        self._tcp = TcpClient(host, port, None, False)
        if timeout is None:
            timeout = defaults.tbvnetworkinterface_timeout
        self._timeout = timeout
        if connect is None:
            connect = defaults.tbvnetworkinterface_connect
        if connect:
            self.connect()
コード例 #10
0
    def __init__(self, device_ID=0, error_screen=True):
        """Create a Cedrus Device Input.

        Notes
        -----
        If no Cedrus device is connected, an error text screen will be
        presented informing that the device could not be found and suggesting
        to check the connection and to switch on the device. After keypress the
        class tries to reconnect with the device. Use <q> to quit this
        procedure.

        Parameters
        ----------
        device_id : int, optional
            device ID (default=0). Only required if more than one
            Cedrus Devices are connected.
        error_screen : bool, optional
            set False to switch off the 'device not found' error screen.
            An exception will be raise instead (default=True)

        """

        Input.__init__(self)
        if type(_pyxid) is not types.ModuleType:
            message = """CedrusDevice can not be initialized, because the Python package
            'pyxid' is not installed. See Expyriment online documentation."""
            raise ImportError(message)

        while True:
            devices = _pyxid.get_xid_devices()
            if len(devices) < 1:
                message = "Could not find a Cedrus Device. Please check the connection and \n"\
                + " ensure that the device is switch on."
            else:
                if not devices[device_ID].is_response_device():
                    message = "Cedrus Device #{0} is not a response device.".format(
                        device_ID)
                else:
                    self._xid = devices[device_ID]
                    break
            if error_screen and expyriment._active_exp.is_initialized:
                expyriment.stimuli.TextScreen(
                    "Error", message +
                    " Press a key to reconnect to the device.").present()
                expyriment._active_exp.keyboard.wait()
                expyriment.stimuli.BlankScreen().present()
                expyriment._active_exp.clock.wait(300)
            else:
                raise IOError(message)

        self._xid.reset_base_timer()
        self._xid.reset_rt_timer()
        self._device_ID = device_ID
        self._buffer = expyriment.misc.Buffer(
            name="Cedrus Device {0}".format(device_ID))
コード例 #11
0
    def __init__(self, device_ID=0, error_screen=True):
        """Create a Cedrus Device Input.

        Notes
        -----
        If no Cedrus device is connected, an error text screen will be
        presented informing that the device could not be found and suggesting
        to check the connection and to switch on the device. After keypress the
        class tries to reconnect with the device. Use <q> to quit this
        procedure.

        Parameters
        ----------
        device_id : int, optional
            device ID (default=0). Only required if more than one
            Cedrus Devices are connected.
        error_screen : bool, optional
            set False to switch off the 'device not found' error screen.
            An exception will be raise instead (default=True)

        """

        Input.__init__(self)
        if not isinstance(_pyxid, ModuleType):
            message = """CedrusDevice can not be initialized, because the Python package
            'pyxid' is not installed. See Expyriment online documentation."""
            raise ImportError(message)

        while True:
            devices = _pyxid.get_xid_devices()
            if len(devices) < 1:
                message = "Could not find a Cedrus Device. Please check the connection and \n"\
                + " ensure that the device is switch on."
            else:
                if not devices[device_ID].is_response_device():
                    message = "Cedrus Device #{0} is not a response device.".format(
                                                                    device_ID)
                else:
                    self._xid = devices[device_ID]
                    break
            if error_screen and _internals.active_exp.is_initialized:
                stimuli.TextScreen("Error", message +
                        " Press a key to reconnect to the device.").present()
                _internals.active_exp.keyboard.wait()
                stimuli.BlankScreen().present()
                _internals.active_exp.clock.wait(300)
            else:
                raise IOError(message)

        self._xid.reset_base_timer()
        self._xid.reset_rt_timer()
        self._device_ID = device_ID
        self._buffer = misc.Buffer(name="Cedrus Device {0}".format(
                                                        device_ID))
コード例 #12
0
ファイル: __init__.py プロジェクト: fnielsen/expyriment
    def __init__(self, address, reverse=False):
        """Create a parallel port input and output.

        Parameters
        ----------
        address : hex or str
            The address of the port to use.
        reverse : bool
            Whether the port should be in reverse mode (default=False).
            Reverse mode enables to read from the data pins.

        Notes
        -----
        On Windows, common port addresses are::
            LPT1 = 0x0378 or 0x03BC
            LPT2 = 0x0278 or 0x0378
            LPT3 = 0x0278

        On Linux, port addresses are in the following format::
            /dev/parport0

        """

        import types
        if type(_ParallelPort) is types.NoneType:
            if sys.platform == "win32":
                _message = "Please install one of the following parallel port " + \
"drivers: 'input32' (http://www.highrez.co.uk/Downloads/InpOut32/) or " + \
"'dlportio' (http://real.kiev.ua/2010/11/29/dlportio-and-32-bit-windows/)."
            elif sys.platform.startswith("linux"):
                _message = "Please install the Python package 'PyParallel'."
            else:
                _message = "Not available on your computer."
            message = "ParallelPort can not be initialized! {0}".format(
                _message)
            raise ImportError(message)

        Input.__init__(self)
        Output.__init__(self)
        if isinstance(address, basestring) and address.startswith('0x'):
            address = int(address, 16)
        self._address = address
        try:
            self._parallel = _ParallelPort(address=address)
        except:
            raise RuntimeError(
                "Could not initiate parallel port at {0}".format(address))
        self.input_history = False  # dummy
        self._reverse = reverse
コード例 #13
0
    def __init__(self, address, reverse=False):
        """Create a parallel port input and output.

        Parameters
        ----------
        address : hex or str
            The address of the port to use.
        reverse : bool
            Whether the port should be in reverse mode (default=False).
            Reverse mode enables to read from the data pins.

        Notes
        -----
        On Windows, common port addresses are::
            LPT1 = 0x0378 or 0x03BC
            LPT2 = 0x0278 or 0x0378
            LPT3 = 0x0278

        On Linux, port addresses are in the following format::
            /dev/parport0

        """

        import types
        if type(_ParallelPort) is types.NoneType:
            if sys.platform == "win32":
                _message = "Please install one of the following parallel port " + \
"drivers: 'input32' (http://www.highrez.co.uk/Downloads/InpOut32/) or " + \
"'dlportio' (http://real.kiev.ua/2010/11/29/dlportio-and-32-bit-windows/)."
            elif sys.platform.startswith("linux"):
                _message = "Please install the Python package 'PyParallel'."
            else:
                _message = "Not available on your computer."
            message = "ParallelPort can not be initialized! {0}".format(
                _message)
            raise ImportError(message)

        Input.__init__(self)
        Output.__init__(self)
        if isinstance(address, basestring) and address.startswith('0x'):
            address = int(address, 16)
        self._address = address
        try:
            self._parallel = _ParallelPort(address=address)
        except:
            raise RuntimeError(
                "Could not initiate parallel port at {0}".format(address))
        self.input_history = False  # dummy
        self._reverse = reverse
コード例 #14
0
    def __init__(self, device, buffer_size=1024):
        """Create a MIDI input.

        Parameters
        ----------
        device : int or str
            id or name of the MIDI device
        buffer_size : int, optional
            number of events to be buffered (default=1024)

        """

        if not isinstance(_midi, ModuleType):
            raise ImportError("""Sorry, MIDI input is not supported on this computer.""")

        if not _internals.active_exp.is_initialized:
            raise RuntimeError(
                "Cannot create MidiIn before expyriment.initialize()!")
        _midi.init()
        Input.__init__(self)
        self._id = device
        self._buffer_size = buffer_size
        self.input = _midi.Input(device, buffer_size)