Esempio n. 1
0
def initialize(
        hardware_server: bool = False,
        hardware_server_socket: str = None) \
        -> ThreadManager:
    """
    Initialize the Opentrons hardware returning a hardware instance.

    :param hardware_server: Run a jsonrpc server allowing rpc to the  hardware
     controller. Only works on buildroot because extra dependencies are
     required.
    :param hardware_server_socket: Override for the hardware server socket
    """
    checked_socket = hardware_server_socket\
        or "/var/run/opentrons-hardware.sock"
    robot_conf = robot_configs.load()
    logging_config.log_init(robot_conf.log_level)

    log.info(f"API server version:  {__version__}")
    log.info(f"Robot Name: {name()}")

    loop = asyncio.get_event_loop()
    hardware = loop.run_until_complete(initialize_robot())

    if hardware_server:
        #  TODO: BC 2020-02-25 adapt hardware socket server to ThreadManager
        loop.run_until_complete(
            install_hardware_server(checked_socket, hardware))  # type: ignore

    return hardware
Esempio n. 2
0
def run(hardware, **kwargs):  # noqa(C901)
    """
    This function was necessary to separate from main() to accommodate for
    server startup path on system 3.0, which is server.main. In the case where
    the api is on system 3.0, server.main will redirect to this function with
    an additional argument of 'patch_old_init'. kwargs are hence used to allow
    the use of different length args
    """
    loop = asyncio.get_event_loop()

    if ff.use_protocol_api_v2():
        robot_conf = loop.run_until_complete(hardware.get_config())
    else:
        robot_conf = hardware.config

    logging_config.log_init(robot_conf.log_level)

    log.info("API server version:  {}".format(__version__))
    if not os.environ.get("ENABLE_VIRTUAL_SMOOTHIE"):
        initialize_robot(loop, hardware)
        if ff.use_protocol_api_v2():
            loop.run_until_complete(hardware.cache_instruments())
        if not ff.disable_home_on_boot():
            log.info("Homing Z axes")
            if ff.use_protocol_api_v2():
                loop.run_until_complete(hardware.home_z())
            else:
                hardware.home_z()
        try:
            udev.setup_rules_file()
        except Exception:
            log.exception(
                "Could not setup udev rules, modules may not be detected")

    if kwargs.get('hardware_server'):
        if ff.use_protocol_api_v2():
            loop.run_until_complete(
                install_hardware_server(kwargs['hardware_server_socket'],
                                        hardware._api))
        else:
            log.warning(
                "Hardware server requested but apiv1 selected, not starting")
    server.run(
        hardware,
        kwargs.get('hostname'),
        kwargs.get('port'),
        kwargs.get('path'),
        loop)