Пример #1
0
    def __init__(self, tdt_params):
        legal_keys = ['TYPE', 'TDT_MODEL', 'TDT_CIRCUIT_PATH', 'TDT_INTERFACE',
                      'TDT_DELAY']
        if tdt_params is None:
            tdt_params = {'TYPE': 'tdt'}
        if not isinstance(tdt_params, dict):
            raise TypeError('tdt_params must be a dictionary.')
        for k in legal_keys:
            if k not in tdt_params.keys() and k != 'TYPE':
                tdt_params[k] = get_config(k, None)

        # Fix a couple keys
        if tdt_params['TDT_DELAY'] is None:
            tdt_params['TDT_DELAY'] = '0'
        tdt_params['TDT_DELAY'] = int(tdt_params['TDT_DELAY'])
        tdt_params['TDT_DELAY'] = int(tdt_params['TDT_DELAY'])
        if tdt_params['TDT_MODEL'] is None:
            tdt_params['TDT_MODEL'] = 'dummy'

        # Check keys
        for k in tdt_params.keys():
            if k not in legal_keys:
                raise KeyError('Unrecognized key in tdt_params: {0}'.format(k))
        self._model = tdt_params['TDT_MODEL']

        if tdt_params['TDT_CIRCUIT_PATH'] is None and self._model != 'dummy':
            cl = dict(RM1='RM1', RP2='RM1', RZ6='RZ6')
            self._circuit = op.join(op.dirname(__file__), 'data',
                                    'expCircuitF32_' + cl[self._model] +
                                    '.rcx')
        else:
            self._circuit = tdt_params['TDT_CIRCUIT_PATH']
        if self._model != 'dummy' and not op.isfile(self._circuit):
            raise IOError('Could not find file {}'.format(self._circuit))
        if tdt_params['TDT_INTERFACE'] is None:
            tdt_params['TDT_INTERFACE'] = 'USB'
        self._interface = tdt_params['TDT_INTERFACE']

        # initialize RPcoX connection
        """
        # HIGH-LEVEL APPROACH, fails possibly due to zBUS call in DSPCircuit
        self.rpcox = tdt.DSPCircuit(circuit, tdt_type, interface=interface)
        self.rpcox.start()

        # LOW-LEVEL APPROACH (works reliably, but no device abstraction)
        self.rpcox = tdt.actxobjects.RPcoX()
        self.connection = self.rpcox.ConnectRM1(IntName=interface, DevNum=1)
        """
        # MID-LEVEL APPROACH
        if connect_rpcox is not None:
            try:
                self.rpcox = connect_rpcox(name=self.model,
                                           interface=self.interface,
                                           device_id=1, address=None)
            except Exception as exp:
                raise OSError('Could not connect to {}, is it turned on? '
                              '(TDT message: "{}")'.format(self._model, exp))
        else:
            self.rpcox = DummyRPcoX(self._model, self._interface)

        if self.rpcox is not None:
            logger.info('Expyfun: RPcoX connection established')
        else:
            raise IOError('Problem initializing RPcoX.')
        """
        # start zBUS (may be needed for devices other than RM1)
        self.zbus = connect_zbus(interface=interface)
        if self.zbus is not None:
            logger.info('Expyfun: zBUS connection established')
        else:
            raise ExperimentError('Problem initializing zBUS.')
        """
        # load circuit
        if not self.rpcox.LoadCOF(self.circuit):
            logger.debug('Expyfun: Problem loading circuit. Clearing...')
            try:
                if self.rpcox.ClearCOF():
                    logger.debug('Expyfun: TDT circuit cleared')
                time.sleep(0.25)
                if not self.rpcox.LoadCOF(self.circuit):
                    raise RuntimeError('Second loading attempt failed')
            except:
                raise IOError('Expyfun: Problem loading circuit.')
        logger.info('Expyfun: Circuit loaded to {1} via {2}:\n{0}'
                    ''.format(self.circuit, self.model, self.interface))
        # run circuit
        if self.rpcox.Run():
            logger.info('Expyfun: TDT circuit running')
        else:
            raise SystemError('Expyfun: Problem starting TDT circuit.')
        time.sleep(0.25)
        self.rpcox.SetTagVal('phase', -1)
        self.clear_buffer()
        self._set_delay(tdt_params['TDT_DELAY'])
Пример #2
0
    def __init__(self, tdt_params):
        legal_keys = ['TYPE', 'TDT_MODEL', 'TDT_CIRCUIT_PATH', 'TDT_INTERFACE',
                      'TDT_DELAY', 'TDT_TRIG_DELAY']
        tdt_params = dict(TYPE='tdt') if tdt_params is None else tdt_params
        tdt_params = deepcopy(tdt_params)
        if not isinstance(tdt_params, dict):
            raise TypeError('tdt_params must be a dict, got '
                            '{0}'.format(type(tdt_params)))
        if tdt_params['TYPE'] != 'tdt':
            raise ValueError('tdt_params["TYPE"] must be "tdt", not '
                             '{0}'.format(tdt_params['TYPE']))
        # Set sensible defaults for values that are not passed
        defaults = dict(TDT_MODEL='dummy', TDT_DELAY='0', TDT_TRIG_DELAY='0',
                        TYPE='tdt')  # if not listed -> None
        for k in legal_keys:
            tdt_params[k] = tdt_params.get(
                k, get_config(k, defaults.get(k, None)))
        for key in ('TDT_DELAY', 'TDT_TRIG_DELAY'):
            tdt_params[key] = int(tdt_params[key])
        if tdt_params['TDT_DELAY'] < 0:
            raise ValueError('tdt_delay must be non-negative.')

        # Check keys
        for k in tdt_params.keys():
            if k not in legal_keys:
                raise KeyError('Unrecognized key in tdt_params {0}, must be '
                               'one of {1}'.format(k, ', '.join(legal_keys)))
        self._model = tdt_params['TDT_MODEL']
        legal_models = ['RM1', 'RP2', 'RZ6', 'RP2legacy', 'dummy']
        if self.model not in legal_models:
            raise ValueError('TDT_MODEL="{0}" must be one of '
                             '{1}'.format(self.model, legal_models))

        if tdt_params['TDT_CIRCUIT_PATH'] is None and self.model != 'dummy':
            cl = dict(RM1='RM1', RP2='RM1', RP2legacy='RP2legacy', RZ6='RZ6')
            self._circuit = op.join(op.dirname(__file__), 'data',
                                    'expCircuitF32_' + cl[self._model] +
                                    '.rcx')
        else:
            self._circuit = tdt_params['TDT_CIRCUIT_PATH']
        if self.model != 'dummy' and not op.isfile(self._circuit):
            raise IOError('Could not find file {}'.format(self._circuit))
        if tdt_params['TDT_INTERFACE'] is None:
            tdt_params['TDT_INTERFACE'] = 'USB'
        self._interface = tdt_params['TDT_INTERFACE']

        # initialize RPcoX connection
        """
        # HIGH-LEVEL APPROACH, fails possibly due to zBUS call in DSPCircuit
        self.rpcox = tdt.DSPCircuit(circuit, tdt_type, interface=interface)
        self.rpcox.start()

        # LOW-LEVEL APPROACH (works reliably, but no device abstraction)
        self.rpcox = tdt.actxobjects.RPcoX()
        self.connection = self.rpcox.ConnectRM1(IntName=interface, DevNum=1)
        """
        # MID-LEVEL APPROACH
        if tdt_params['TDT_MODEL'] != 'dummy':
            from tdt.util import connect_rpcox
            use_model = self.model if self.model != 'RP2legacy' else 'RP2'
            try:
                self.rpcox = connect_rpcox(name=use_model,
                                           interface=self.interface,
                                           device_id=1, address=None)
            except Exception as exp:
                raise OSError('Could not connect to {}, is it turned on? '
                              '(TDT message: "{}")'.format(self._model, exp))
        else:
            msg = ('TDT is in dummy mode. No sound or triggers will '
                   'be produced. Check TDT configuration and TDTpy '
                   'installation.')
            logger.warning(msg)  # log it
            warnings.warn(msg)  # make it red
            self.rpcox = DummyRPcoX(self._model, self._interface)

        if self.rpcox is not None:
            logger.info('Expyfun: RPcoX connection established')
        else:
            raise IOError('Problem initializing RPcoX.')
        """
        # start zBUS (may be needed for devices other than RM1)
        self.zbus = connect_zbus(interface=interface)
        if self.zbus is not None:
            logger.info('Expyfun: zBUS connection established')
        else:
            raise ExperimentError('Problem initializing zBUS.')
        """
        # load circuit
        if not self.rpcox.LoadCOF(self.circuit):
            logger.debug('Expyfun: Problem loading circuit. Clearing...')
            try:
                if self.rpcox.ClearCOF():
                    logger.debug('Expyfun: TDT circuit cleared')
                time.sleep(0.25)
                if not self.rpcox.LoadCOF(self.circuit):
                    raise RuntimeError('Second loading attempt failed')
            except Exception:
                raise IOError('Expyfun: Problem loading circuit.')
        logger.info('Expyfun: Circuit loaded to {1} via {2}:\n{0}'
                    ''.format(self.circuit, self.model, self.interface))
        # run circuit
        if self.rpcox.Run():
            logger.info('Expyfun: TDT circuit running')
        else:
            raise SystemError('Expyfun: Problem starting TDT circuit.')
        time.sleep(0.25)
        self._set_noise_corr()
        self._set_delay(tdt_params['TDT_DELAY'],
                        tdt_params['TDT_TRIG_DELAY'])
        # Set output values to zero (esp. first few)
        for tag in ('datainleft', 'datainright'):
            self.rpcox.ZeroTag(tag)
        self.rpcox.SetTagVal('trgname', 0)
        self._used_params = tdt_params
Пример #3
0
    def __init__(self, tdt_params):
        legal_keys = [
            'TYPE', 'TDT_MODEL', 'TDT_CIRCUIT_PATH', 'TDT_INTERFACE',
            'TDT_DELAY', 'TDT_TRIG_DELAY'
        ]
        tdt_params = dict(TYPE='tdt') if tdt_params is None else tdt_params
        tdt_params = deepcopy(tdt_params)
        if not isinstance(tdt_params, dict):
            raise TypeError('tdt_params must be a dict, got '
                            '{0}'.format(type(tdt_params)))
        if tdt_params['TYPE'] != 'tdt':
            raise ValueError('tdt_params["TYPE"] must be "tdt", not '
                             '{0}'.format(tdt_params['TYPE']))
        # Set sensible defaults for values that are not passed
        defaults = dict(TDT_MODEL='dummy',
                        TDT_DELAY='0',
                        TDT_TRIG_DELAY='0',
                        TYPE='tdt')  # if not listed -> None
        for k in legal_keys:
            tdt_params[k] = tdt_params.get(
                k, get_config(k, defaults.get(k, None)))
        for key in ('TDT_DELAY', 'TDT_TRIG_DELAY'):
            tdt_params[key] = int(tdt_params[key])
        if tdt_params['TDT_DELAY'] < 0:
            raise ValueError('tdt_delay must be non-negative.')

        # Check keys
        for k in tdt_params.keys():
            if k not in legal_keys:
                raise KeyError('Unrecognized key in tdt_params {0}, must be '
                               'one of {1}'.format(k, ', '.join(legal_keys)))
        self._model = tdt_params['TDT_MODEL']
        legal_models = ['RM1', 'RP2', 'RZ6', 'RP2legacy', 'dummy']
        if self.model not in legal_models:
            raise ValueError('TDT_MODEL="{0}" must be one of '
                             '{1}'.format(self.model, legal_models))

        if tdt_params['TDT_CIRCUIT_PATH'] is None and self.model != 'dummy':
            cl = dict(RM1='RM1', RP2='RM1', RP2legacy='RP2legacy', RZ6='RZ6')
            self._circuit = op.join(
                op.dirname(__file__), 'data',
                'expCircuitF32_' + cl[self._model] + '.rcx')
        else:
            self._circuit = tdt_params['TDT_CIRCUIT_PATH']
        if self.model != 'dummy' and not op.isfile(self._circuit):
            raise IOError('Could not find file {}'.format(self._circuit))
        if tdt_params['TDT_INTERFACE'] is None:
            tdt_params['TDT_INTERFACE'] = 'USB'
        self._interface = tdt_params['TDT_INTERFACE']

        # initialize RPcoX connection
        """
        # HIGH-LEVEL APPROACH, fails possibly due to zBUS call in DSPCircuit
        self.rpcox = tdt.DSPCircuit(circuit, tdt_type, interface=interface)
        self.rpcox.start()

        # LOW-LEVEL APPROACH (works reliably, but no device abstraction)
        self.rpcox = tdt.actxobjects.RPcoX()
        self.connection = self.rpcox.ConnectRM1(IntName=interface, DevNum=1)
        """
        # MID-LEVEL APPROACH
        if tdt_params['TDT_MODEL'] != 'dummy':
            from tdt.util import connect_rpcox
            use_model = self.model if self.model != 'RP2legacy' else 'RP2'
            try:
                self.rpcox = connect_rpcox(name=use_model,
                                           interface=self.interface,
                                           device_id=1,
                                           address=None)
            except Exception as exp:
                raise OSError('Could not connect to {}, is it turned on? '
                              '(TDT message: "{}")'.format(self._model, exp))
        else:
            msg = ('TDT is in dummy mode. No sound or triggers will '
                   'be produced. Check TDT configuration and TDTpy '
                   'installation.')
            logger.warning(msg)  # log it
            warnings.warn(msg)  # make it red
            self.rpcox = DummyRPcoX(self._model, self._interface)

        if self.rpcox is not None:
            logger.info('Expyfun: RPcoX connection established')
        else:
            raise IOError('Problem initializing RPcoX.')
        """
        # start zBUS (may be needed for devices other than RM1)
        self.zbus = connect_zbus(interface=interface)
        if self.zbus is not None:
            logger.info('Expyfun: zBUS connection established')
        else:
            raise ExperimentError('Problem initializing zBUS.')
        """
        # load circuit
        if not self.rpcox.LoadCOF(self.circuit):
            logger.debug('Expyfun: Problem loading circuit. Clearing...')
            try:
                if self.rpcox.ClearCOF():
                    logger.debug('Expyfun: TDT circuit cleared')
                time.sleep(0.25)
                if not self.rpcox.LoadCOF(self.circuit):
                    raise RuntimeError('Second loading attempt failed')
            except Exception:
                raise IOError('Expyfun: Problem loading circuit.')
        logger.info('Expyfun: Circuit loaded to {1} via {2}:\n{0}'
                    ''.format(self.circuit, self.model, self.interface))
        # run circuit
        if self.rpcox.Run():
            logger.info('Expyfun: TDT circuit running')
        else:
            raise SystemError('Expyfun: Problem starting TDT circuit.')
        time.sleep(0.25)
        self._set_noise_corr()
        self._set_delay(tdt_params['TDT_DELAY'], tdt_params['TDT_TRIG_DELAY'])
        # Set output values to zero (esp. first few)
        for tag in ('datainleft', 'datainright'):
            self.rpcox.ZeroTag(tag)
        self.rpcox.SetTagVal('trgname', 0)
        self._used_params = tdt_params
Пример #4
0
    def __init__(self, tdt_params):
        legal_keys = [
            'TYPE', 'TDT_MODEL', 'TDT_CIRCUIT_PATH', 'TDT_INTERFACE',
            'TDT_DELAY', 'TDT_TRIG_DELAY'
        ]
        if tdt_params is None:
            tdt_params = {'TYPE': 'tdt'}
        tdt_params = deepcopy(tdt_params)
        if not isinstance(tdt_params, dict):
            raise TypeError('tdt_params must be a dictionary.')
        for k in legal_keys:
            if k not in tdt_params.keys() and k != 'TYPE':
                tdt_params[k] = get_config(k, None)

        # Fix a couple keys
        if tdt_params['TDT_DELAY'] is None:
            tdt_params['TDT_DELAY'] = '0'
        if tdt_params['TDT_TRIG_DELAY'] is None:
            tdt_params['TDT_TRIG_DELAY'] = '0'
        tdt_params['TDT_DELAY'] = int(tdt_params['TDT_DELAY'])
        tdt_params['TDT_TRIG_DELAY'] = int(tdt_params['TDT_TRIG_DELAY'])
        if tdt_params['TDT_MODEL'] is None or connect_rpcox is None:
            tdt_params['TDT_MODEL'] = 'dummy'

        # Check keys
        for k in tdt_params.keys():
            if k not in legal_keys:
                raise KeyError('Unrecognized key in tdt_params: {0}'.format(k))
        self._model = tdt_params['TDT_MODEL']

        if tdt_params['TDT_CIRCUIT_PATH'] is None and self._model != 'dummy':
            cl = dict(RM1='RM1', RP2='RM1', RZ6='RZ6')
            self._circuit = op.join(
                op.dirname(__file__), 'data',
                'expCircuitF32_' + cl[self._model] + '.rcx')
        else:
            self._circuit = tdt_params['TDT_CIRCUIT_PATH']
        if self._model != 'dummy' and not op.isfile(self._circuit):
            raise IOError('Could not find file {}'.format(self._circuit))
        if tdt_params['TDT_INTERFACE'] is None:
            tdt_params['TDT_INTERFACE'] = 'USB'
        self._interface = tdt_params['TDT_INTERFACE']

        # initialize RPcoX connection
        """
        # HIGH-LEVEL APPROACH, fails possibly due to zBUS call in DSPCircuit
        self.rpcox = tdt.DSPCircuit(circuit, tdt_type, interface=interface)
        self.rpcox.start()

        # LOW-LEVEL APPROACH (works reliably, but no device abstraction)
        self.rpcox = tdt.actxobjects.RPcoX()
        self.connection = self.rpcox.ConnectRM1(IntName=interface, DevNum=1)
        """
        # MID-LEVEL APPROACH
        if tdt_params['TDT_MODEL'] != 'dummy':
            try:
                self.rpcox = connect_rpcox(name=self.model,
                                           interface=self.interface,
                                           device_id=1,
                                           address=None)
            except Exception as exp:
                raise OSError('Could not connect to {}, is it turned on? '
                              '(TDT message: "{}")'.format(self._model, exp))
        else:
            msg = ('TDT is in dummy mode. No sound or triggers will '
                   'be produced. Check TDT configuration and TDTpy '
                   'installation.')
            logger.warning(msg)  # log it
            warnings.warn(msg)  # make it red
            self.rpcox = DummyRPcoX(self._model, self._interface)

        if self.rpcox is not None:
            logger.info('Expyfun: RPcoX connection established')
        else:
            raise IOError('Problem initializing RPcoX.')
        """
        # start zBUS (may be needed for devices other than RM1)
        self.zbus = connect_zbus(interface=interface)
        if self.zbus is not None:
            logger.info('Expyfun: zBUS connection established')
        else:
            raise ExperimentError('Problem initializing zBUS.')
        """
        # load circuit
        if not self.rpcox.LoadCOF(self.circuit):
            logger.debug('Expyfun: Problem loading circuit. Clearing...')
            try:
                if self.rpcox.ClearCOF():
                    logger.debug('Expyfun: TDT circuit cleared')
                time.sleep(0.25)
                if not self.rpcox.LoadCOF(self.circuit):
                    raise RuntimeError('Second loading attempt failed')
            except:
                raise IOError('Expyfun: Problem loading circuit.')
        logger.info('Expyfun: Circuit loaded to {1} via {2}:\n{0}'
                    ''.format(self.circuit, self.model, self.interface))
        # run circuit
        if self.rpcox.Run():
            logger.info('Expyfun: TDT circuit running')
        else:
            raise SystemError('Expyfun: Problem starting TDT circuit.')
        time.sleep(0.25)
        self._set_noise_corr()
        self.clear_buffer()
        self._set_delay(tdt_params['TDT_DELAY'], tdt_params['TDT_TRIG_DELAY'])