Пример #1
0
    def configure_driver(self, config: DriverConfig, number: str,
                         platform_settings: dict) -> FASTDriver:
        """Configure a driver.

        Args:
        ----
            config: Driver config.
            number: Number of this driver.
            platform_settings: Platform specific settings.

        Returns: Driver object
        """
        # dont modify the config. make a copy
        platform_settings = deepcopy(platform_settings)

        if not self.net_connection:
            raise AssertionError('A request was made to configure a FAST '
                                 'driver, but no connection to a NET processor'
                                 'is available')

        if not number:
            raise AssertionError("Driver needs a number")

        # If we have WPC driver boards, look up the driver number
        if self.machine_type == 'wpc':
            try:
                number = fast_defines.WPC_DRIVER_MAP[number.upper()]
            except KeyError:
                self.raise_config_error(
                    "Could not find WPC driver {}".format(number), 1)

            if ('connection' in platform_settings
                    and platform_settings['connection'].lower() == 'network'):
                platform_settings['connection'] = 1
            else:
                platform_settings[
                    'connection'] = 0  # local driver (default for WPC)

        # If we have FAST IO boards, we need to make sure we have hex strings
        elif self.machine_type == 'fast':

            number = self._parse_driver_number(number)

            # Now figure out the connection type
            if ('connection' in platform_settings
                    and platform_settings['connection'].lower() == 'local'):
                platform_settings['connection'] = 0
            else:
                platform_settings[
                    'connection'] = 1  # network driver (default for FAST)

        else:
            raise AssertionError("Invalid machine type: {}".format(
                self.machine_type))

        return FASTDriver(config, self, number, platform_settings)
Пример #2
0
    def configure_driver(self, config: dict) -> FASTDriver:
        """Configure a driver.

        Args:
            config: Driver config.

        Returns: Driver object
        """
        # dont modify the config. make a copy
        config = deepcopy(config)

        if not self.net_connection:
            raise AssertionError('A request was made to configure a FAST '
                                 'driver, but no connection to a NET processor'
                                 'is available')

        if not config['number']:
            raise AssertionError("Driver needs a number")

        # If we have WPC driver boards, look up the driver number
        if self.machine_type == 'wpc':
            config['number'] = fast_defines.wpc_driver_map.get(
                config['number'].upper())

            if ('connection' in config
                    and config['connection'].lower() == 'network'):
                config['connection'] = 1
            else:
                config['connection'] = 0  # local driver (default for WPC)

        # If we have FAST IO boards, we need to make sure we have hex strings
        elif self.machine_type == 'fast':

            config['number'] = self._parse_driver_number(config['number'])

            # Now figure out the connection type
            if ('connection' in config
                    and config['connection'].lower() == 'local'):
                config['connection'] = 0
            else:
                config['connection'] = 1  # network driver (default for FAST)

        else:
            raise AssertionError("Invalid machine type: {}".format(
                self.machine_type))

        return FASTDriver(config, self.net_connection.send, self.machine, self)