def connect_backend(self, backend_name=None):
        """
        Connect to the driver backend. If none is specified then a
        default value for the given platform will be guessed.

        :param backend_name: Name of backend, defaults to None
        :type backend_name: str, optional
        :return: True on success.
        :rtype: bool

        """
        if backend_name is None:
            backend_name = get_backend_for_os()

        logging.info(f'SDI:connect_backend: backend={backend_name}')

        self.backend = get_backend(backend_name)

        rc = self.backend.connect()
        if not rc:
            logging.error('Failed to connect to backend!')

        # set all backends
        self.camera_backend = self.backend
        self.focuser_backend = self.backend
        self.filterwheel_backend = self.backend

        return rc
    def connect_filterwheel(self, driver, backend_name=None):
        """
        Connect to the filterwheel driver.  A backend can be specified so that
        the filterwheel uses a different backend than other device classes, for
        example.

        :param driver: Name of filterwheel driver.
        :type driver: str
        :param backend_name: Name of backend to use for filterwheel, defaults to None
        :type backend_name: str, optional
        :return: FilterWheel object or None if connection fails.
        :rtype: FilterWheel object

        """
        rc = None

        # if backend_name is None we assume they connected with connect_backend
        # and all devices share the same backend
        if backend_name is not None:
            logging.info('SDI:connect_filterwheel: '
                         f'filterwheel_backend={backend_name}')

            self.filterwheel_backend = get_backend(backend_name)

            rc = self.filterwheel_backend.connect()
            if not rc:
                logging.error('Failed to connect to backend!')
                return None
        else:
            if self.filterwheel_backend is not None:
                backend_name = self.filterwheel_backend.name()
            else:
                backend_name = None

        if backend_name is None:
            logging.error('No backend specified! Cannot connect filter wheel!')
            return None

        wheel = self.filterwheel_backend.newFilterWheel()
        rc = wheel.connect(driver)

        if rc:
            return wheel
        else:
            return None
Esempio n. 3
0
    def set_mount_backend(self, backend_name):
        """
        Set the backend for the mount device.

        :param backendname: Name of the mount backend.
        :type backendname: str
        """

        #FIXME Need error checking!
        self.mount_backend.set_backend(get_backend(backend_name))
        mount_dev = self.mount_backend.newMount()
        MountManagerClass = type('MountManager', (MountManager,
                                                  type(mount_dev)), {})
        logging.debug(f'mount_dev={mount_dev} '
                      f'MountManagerClass={MountManagerClass}')
        self.mount.set_device(MountManagerClass(self.mount_backend))
        logging.debug(f'set_mount_backend: self.mount = {self.mount}')
        logging.debug(f'set_mount_backend: self.mount.has_chooser = '
                      f'{self.mount.has_chooser}')
Esempio n. 4
0
    def set_camera_backend(self, backend_name):
        """
        Set the backend for the camera device.

        :param backendname: Name of the camera backend.
        :type backendname: str
        """

        #FIXME Need error checking!
        logging.debug(f'set_camera_backend to {backend_name}')
        self.camera_backend.set_backend(get_backend(backend_name))
        camera_dev = self.camera_backend.newCamera()
        CameraManagerClass = type('CameraManager', (CameraManager,
                                                    type(camera_dev)), {})
        logging.debug(f'type(camera_dev)={type(camera_dev)}')
        logging.debug(f'camera_dev={dir(camera_dev)} '
                      f'CameraManagerClass={dir(CameraManagerClass)}')
        self.camera.set_device(CameraManagerClass(self.camera_backend))
        logging.debug(f'set_camera_backend: self.camera = {vars(self.camera)}')
Esempio n. 5
0
    def set_filterwheel_backend(self, backend_name):
        """
        Set the backend for the filterwheel device.

        :param backendname: Name of the filterwheel backend.
        :type backendname: str
        """

        #FIXME Need error checking!
        self.filterwheel_backend.set_backend(get_backend(backend_name))
        wheel_dev = self.filterwheel_backend.newFilterWheel()
        FilterWheelManagerClass = type('FilterWheelManager',
                                       (FilterWheelManager, type(wheel_dev)), {})
        logging.debug(f'wheel_dev={wheel_dev} '
                      f'FilterWheelManagerClass={FilterWheelManagerClass}')
        self.filterwheel.set_device(FilterWheelManagerClass(self.filterwheel_backend))
        logging.debug(f'set_filterwheel_backend: '
                      f'self.filterwheel = {self.filterwheel}')
        logging.debug(f'set_filterwheel_backend: self.filterwheel.has_chooser '
                      f'= {self.filterwheel.has_chooser}')
Esempio n. 6
0
    def set_focuser_backend(self, backend_name):
        """
        Set the backend for the focuser device.

        :param backendname: Name of the focuser backend.
        :type backendname: str
        """

        #FIXME Need error checking!
        logging.debug(f'set_focuser_backend to {backend_name}')
        self.focuser_backend.set_backend(get_backend(backend_name))
        focuser_dev = self.focuser_backend.newFocuser()
        FocuserManagerClass = type('FocuserManager', (FocuserManager,
                                                      type(focuser_dev)), {})
        logging.debug(f'focuser_dev={focuser_dev} '
                      f'FocuserManagerClass={FocuserManagerClass}')
        self.focuser.set_device(FocuserManagerClass(self.focuser_backend))
        logging.debug(f'set_focuser_backend: self.focuser = {self.focuser}')
        logging.debug(f'set_focuser_backend: self.focuser.has_chooser '
                      f'= {self.focuser.has_chooser}')
    args = parser.parse_args()
    logging.info(f'command args = {args}')

    if args.backend is None:
        logging.error('Must supply name of backend to use!')
        sys.exit(1)

    if args.driver is None:
        logging.error('Must supply name of driver to use!')
        sys.exit(1)

    if args.debug:
        CH.setLevel(logging.DEBUG)

    logging.info(f'connecting to backend {args.backend}')
    backend = get_backend(args.backend)
    rc = backend.connect()

    logging.info(f'result of connect to backend = {rc}')
    if not rc:
        sys.exit(-1)

    # connect to focuser
    focuser = backend.newFocuser()

    logging.info(f'Connecting to focuser driver {args.driver}')
    rc = focuser.connect(args.driver)
    logging.info(f'connect result = {rc}')

    if not rc:
        logging.error('Failed to connect - quitting')
    def connect_camera(self, camera_driver, backend_name=None):
        """
        Connect to the camera driver.  A backend can be specified so that
        the camera uses a different backend than other device classes, for
        example.

        :param driver: Name of camera driver.
        :type driver: str
        :param backend_name: Name of backend to use for camera, defaults to None
        :type backend_name: str, optional
        :return: Camera object or None if connection fails.
        :rtype: Camera object

        """
        # if backend_name is None we assume they connected with connect_backend
        # and all devices share the same backend
        if backend_name is not None:

            logging.info(f'SDI:connect_camera: camera_backend={backend_name}')

            self.camera_backend = get_backend(backend_name)

            rc = self.camera_backend.connect()
            if not rc:
                logging.error('Failed to connect to backend!')
                return None
        else:
            if self.camera_backend is not None:
                backend_name = self.camera_backend.name()
            else:
                backend_name = None

        logging.info(f'connect_camera: backend_name = {backend_name}')

        if backend_name is None:
            logging.error('No backend specified! Cannot connect camera!')
            return None

        logging.debug(f'connect_camera: driver =  {camera_driver}')

        cam = self.camera_backend.newCamera()

        rc = cam.connect(camera_driver)

    #    if driver == 'INDICamera':
    #        rc = cam.connect(camera_driver)
    #
    ##        if ':' in camera_driver:
    ##            indi_cam_driver = camera_driver.split(':')[1]
    ##            rc = cam.connect(indi_cam_driver)
    ##        else:
    ##            logging.error('connect_camera(): Must configure INDI camera driver first!')
    ##            return None
    #    else:
    #        rc = cam.connect(driver)

        if not rc:
            logging.error('connect_camera(): Unable to connect to camera!')
            return None

        self.camera_driver = camera_driver
        return cam