#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：MicroscopeInterface.py
@Description：
@Author：XSH
@Time：2025/12/10 13:47
@Department：研发部
@Copyright：©2025 乐辰生物
"""
import clr
from typing                                                     import Union
from PyQt5                                                      import Qt
from AppSettings.Settings                                       import *
from abc                                                        import abstractmethod
from AppInterfaces.ImplInterface                                import ImplInterface
from AppContexts.Contexts                                       import *
from AppInterfaces.AppImplInterfaces.MicroscopeInterfaceBase    import MicroscopeInterfaceBase



class MicroscopeInterface(ImplInterface):
    Parameter   : (LeiCaContext, ZeissContext)
    Microscope  : MicroscopeInterfaceBase

    @property
    def hasParameter(self) -> bool:
        return hasattr(self, 'Parameter') and isinstance(self.Parameter, (LeiCaContext, ZeissContext))

    @property
    def hasManager(self) -> bool:
        return hasattr(self, 'Manager') and isinstance(self.Manager, MicroscopeInterfaceBase)

    @property
    def isAvailable(self) -> bool:
        return self.isValid and self.IsOpen

    @property
    def parameter(self) -> Union[LeiCaContext, ZeissContext]:
        return self.Parameter if self.hasParameter else None

    def setParameter(self, value):
        self.Parameter = value if isinstance(value, (LeiCaContext, ZeissContext)) else None

    @property
    def manager(self) -> MicroscopeInterfaceBase:
        return self.Manager if self.hasManager else None

    @property
    def isValid(self) -> bool:
        return self.hasManager and self.hasParameter

    @property
    def IsOpen(self) -> bool:
        return self.isValid and self.Manager.IsOpen

    @property
    def isEnabled(self) -> bool:
        return self.isValid and self.Manager.isEnabled

    @property
    def isDisable(self) -> bool:
        return self.isValid and self.Manager.isDisable


    def Open(self, timeOut: int = 1000, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.Open(timeOut, **args)
        return RECODE_FAILURE

    def Close(self, timeOut: int = 1000, **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.Close(timeOut, **args)
        return RECODE_FAILURE

    def ReOpen(self, timeOut: int = 1000, **args) -> int:
        self.Close(timeOut, **args)
        return self.Open(timeOut, **args)

    @abstractmethod
    def initManager(self, **args):
        pass

    @abstractmethod
    def deleManager(self):
        pass

    @abstractmethod
    def initContext(self):
        pass


    def initMicroscope(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.initMicroscope()
        return RECODE_FAILURE

    def initMicroscopeObjective(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.initMicroscopeObjective()
        return RECODE_FAILURE

    def set_max_lamp(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_max_lamp()
        return RECODE_FAILURE


    def set_min_lamp(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_min_lamp()
        return RECODE_FAILURE


    def set_min_lfbl(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_min_lfbl()
        return RECODE_FAILURE


    def set_max_lfbl(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_max_lfbl()
        return RECODE_FAILURE


    def set_min_apbl(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_min_apbl()
        return RECODE_FAILURE


    def set_max_apbl(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_max_apbl()
        return RECODE_FAILURE


    def set_shutter_lamp(self, enable: (bool, int)) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_shutter_lamp(enable)
        return RECODE_FAILURE


    def get_shutter_lamp(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_shutter_lamp()
        return RECODE_FAILURE, None


    def set_master_event(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_master_event()
        return


    def set_objective_event(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_objective_event()
        return RECODE_FAILURE


    def set_z_event(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_z_event()
        return RECODE_FAILURE


    def set_tl_event(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_tl_event()
        return RECODE_FAILURE


    def set_field_tl_event(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_field_tl_event()
        return RECODE_FAILURE


    def set_led_event(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_led_event()
        return RECODE_FAILURE


    def set_config_mode(self, enable: (int, bool) = 0):
        """设置配置模式 0: 配置模式关闭 1：配置模式开启"""
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_config_mode(enable)
        return RECODE_FAILURE


    def get_config_mode(self):
        """设置配置模式 0: 配置模式关闭 1：配置模式开启"""
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_config_mode()
        return RECODE_FAILURE


    def home(self) -> int:
        if not self.hasManager:
            self.initManager()
        return self.initMicroscope()


    def waithome(self) -> int:
        if not self.hasManager:
            self.initManager()
        return self.initMicroscope()


    def move(self, value: (int, float), mode: int = 1, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.move(value, mode, **args)
        return RECODE_FAILURE


    def set_position(self, position: (int, float)) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_position( position)
        return RECODE_FAILURE


    def stop_move(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.stop_move()
        return RECODE_FAILURE


    def rel_waitmove(self, value: (int, float), mode: int = 1, **args):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.rel_waitmove(value, mode, **args)
        return RECODE_FAILURE


    def waitForNotMoving(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitForNotMoving()
        return RECODE_FAILURE


    def rel_move(self, value: (int, float), mode: int = 1, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.rel_move(value, mode, **args)
        return RECODE_FAILURE


    def waitmove(self, position: (int, float), mode: int = 1, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitmove(position, mode, **args)
        return RECODE_FAILURE


    def waitingToStop(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitingToStop()
        return RECODE_FAILURE


    def isMoveRange(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.isMoveRange()
        return RECODE_FAILURE, None


    def isMoveLower(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.isMoveLower()
        return RECODE_FAILURE, None


    def isMoveUpper(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.isMoveUpper()
        return RECODE_FAILURE, None


    def isMoveFocus(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.isMoveFocus()
        return RECODE_FAILURE, None


    def isMoveMoving(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.isMoveMoving()
        return RECODE_FAILURE, None


    def check_z(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.check_z()
        return RECODE_FAILURE


    def reset_z(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.reset_z()
        return RECODE_FAILURE


    def is_moving(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.is_moving()
        return RECODE_FAILURE


    def get_move_status(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_move_status()
        return RECODE_FAILURE, None


    def waitmove_complete(self, position: (int, float), **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitmove_complete(position, **args)
        return RECODE_FAILURE


    def waitmove_finish(self, position: (int, float), **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitmove_finish(position, **args)
        return RECODE_FAILURE


    def waitmove_lower_limit(self, **args):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitmove_lower_limit(**args)
        return RECODE_FAILURE


    def waitmove_upper_limit(self, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitmove_upper_limit(**args)
        return RECODE_FAILURE


    def waitmove_h_lower_limit(self, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitmove_h_lower_limit(**args)
        return RECODE_FAILURE


    def waitmove_h_upper_limit(self, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.waitmove_h_upper_limit(**args)
        return RECODE_FAILURE


    def get_z_status(self) -> (int, int, int, int, int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_z_status()
        return RECODE_FAILURE, None, None, None, None, None


    def set_focus_position(self, position: (int, float)) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_focus_position(position)
        return RECODE_FAILURE


    def set_focus_limit_active(self, enable: (int, bool)) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_focus_limit_active(enable)
        return RECODE_FAILURE


    def get_focus_limit_active(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_focus_limit_active()
        return RECODE_FAILURE, None


    def is_h_lower_limit(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.is_h_lower_limit()
        return RECODE_FAILURE


    def is_h_upper_limit(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.is_h_upper_limit()
        return RECODE_FAILURE


    def is_s_lower_limit(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.is_s_lower_limit()
        return RECODE_FAILURE


    def is_s_upper_limit(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.is_s_upper_limit()
        return RECODE_FAILURE


    def getPosition(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.getPosition()
        return None


    def setFastSpeedMode(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.setFastSpeedMode()
        return RECODE_FAILURE


    def setNormalSpeedMode(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.setNormalSpeedMode()
        return RECODE_FAILURE


    def changedObjective(self, level: int, is_lower_limit: bool = False, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.changedObjective(level, is_lower_limit, **args)
        return RECODE_FAILURE


    def set_objective(self, level: int, is_lower_limit: bool = False, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_objective(level, is_lower_limit, **args)
        return RECODE_FAILURE


    def changedLightIntensity(self, level: int, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.changedLightIntensity(level, **args)
        return RECODE_FAILURE


    def set_z_upper_limit(self, limit=-1) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_z_upper_limit(limit)
        return RECODE_FAILURE


    def set_z_lower_limit(self, limit=-1) -> int:
        if self.hasManager:
            return self.manager.set_z_lower_limit(limit)
        return RECODE_FAILURE


    def set_z_upper_enable(self, enable: (int, bool), **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_z_upper_enable(enable, **args)
        return RECODE_FAILURE


    def set_z_lower_enable(self, enable: (int, bool), **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_tl_rl_switch()
        return RECODE_FAILURE


    def init_objective_range(self, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.init_objective_range(**args)
        return RECODE_FAILURE


    def init_z_range(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.init_z_range()
        return RECODE_FAILURE

    def wait_init_z_range(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.wait_init_z_range()
        return RECODE_FAILURE

    def init_z_speed(self, level: int) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.init_z_speed(level)
        return RECODE_FAILURE


    def set_z_range(self, min_limit: int = -1, max_limit: int = -1) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_range(min_limit, max_limit)
        return RECODE_FAILURE


    def get_z_upper_limit(self) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_upper_limit()
        return RECODE_FAILURE, None


    def get_z_lower_limit(self) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_lower_limit()
        return RECODE_FAILURE, None


    def get_z_range(self) -> (int, float, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_range()
        return RECODE_FAILURE, None, None


    def get_z_limit(self) -> (int, float, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_limit()
        return RECODE_FAILURE, None, None


    def set_z_speed(self, speed: (float, int)):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_speed(speed)
        return RECODE_FAILURE


    def get_z_speed(self) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_speed()
        return RECODE_FAILURE, None


    def set_z_acceleration(self, acceleration: (float, int)) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_acceleration(acceleration)
        return RECODE_FAILURE


    def get_z_acceleration(self) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_acceleration()
        return RECODE_FAILURE, None


    def get_z_enabled(self) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_enabled()
        return RECODE_FAILURE


    def set_z_enabled(self, enable: (int, bool)) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_enabled(enable)
        return RECODE_FAILURE


    def setMeasurementOrigin(self, value: (int, float), **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.setMeasurementOrigin(value, **args)
        return RECODE_FAILURE


    def getMeasurementOrigin(self, **args) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.getMeasurementOrigin(**args)
        return RECODE_FAILURE


    def setMeasurementPosition(self, value: (int, float), **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.setMeasurementPosition(value, **args)
        return RECODE_FAILURE


    def getMeasurementPosition(self, **args) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.getMeasurementPosition(**args)
        return RECODE_FAILURE, None


    def set_z_move_mode(self, enable: (int, bool)):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_move_mode(enable)
        return RECODE_FAILURE


    def set_objective_upper_limit(self, level) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_upper_limit(level)
        return RECODE_FAILURE


    def set_objective_limit(self, level) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_limit(level)
        return RECODE_FAILURE


    def set_objective_lower_limit(self, level) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_lower_limit(level)
        return RECODE_FAILURE


    def set_objective_focus_speed(self, level) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_focus_speed(level)
        return RECODE_FAILURE


    def set_objective_default_speed(self, level) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_default_speed(level)
        return RECODE_FAILURE


    def set_objective_scan_speed(self, level) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_scan_speed(level)
        return RECODE_FAILURE


    def set_upper_limit(self, position: (int, float)) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_upper_limit(position)
        return RECODE_FAILURE


    def set_lower_limit(self, position: (int, float)) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_lower_limit()
        return RECODE_FAILURE


    def get_position(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_position()
        return RECODE_FAILURE, None


    def get_z_measurement_origin(self) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_measurement_origin()
        return RECODE_FAILURE, None


    def get_z_measurement_position(self) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_z_measurement_position()
        return RECODE_FAILURE, None


    def set_z_measurement_origin(self, position: (int, float), **args) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_measurement_origin(position, **args)
        return RECODE_FAILURE, None


    def set_z_measurement_position(self, position: (int, float), **args) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_measurement_position(position, **args)
        return RECODE_FAILURE, None


    def set_z_align_position(self, position: (int, float), **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_align_position(position, **args)
        return RECODE_FAILURE


    def getObjective(self) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.getObjective()
        return RECODE_FAILURE


    def get_objective_parameter(self, level: int) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_objective_parameter(level)
        return RECODE_FAILURE, None


    def set_objective_parameter(self, level: int) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_parameter(level)
        return RECODE_FAILURE, None


    def get_objective(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_objective()
        return RECODE_FAILURE, None


    def get_objective_status(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_objective_status()
        return RECODE_FAILURE, None


    def set_objective_mode(self, mode: int) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_mode(mode)
        return RECODE_FAILURE


    def get_objective_mode(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_objective_mode()
        return RECODE_FAILURE, None


    def set_objective_dry(self, dry: int) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_dry(dry)
        return RECODE_FAILURE


    def get_objective_dry(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_objective_dry()
        return RECODE_FAILURE


    def set_objective_dip(self) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_dip()
        return RECODE_FAILURE


    def set_objective_patho_mode(self, mode: int = 0) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_patho_mode(mode)
        return RECODE_FAILURE


    def get_objective_patho_mode(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_objective_patho_mode()
        return RECODE_FAILURE, None


    def set_objective_position(self, position: (int, float)) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_objective_position(position)
        return RECODE_FAILURE


    def get_objective_position(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_objective_position()
        return RECODE_FAILURE, None


    def currentObjective(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.currentObjective()
        return RECODE_FAILURE, None


    def changed_spot_light(self, enable: (bool, int)) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.changed_spot_light(enable)
        return RECODE_FAILURE, None


    def get_spot_light(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.get_spot_light()
        return RECODE_FAILURE, None


    def POS_CONST_Z(self, speed: int, target: int = None, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.POS_CONST_Z(speed, target, ** args)
        return RECODE_FAILURE


    def getHandwheelOnOff(self) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.getHandwheelOnOff()
        return RECODE_FAILURE


    def setHandwheelOnOff(self, enable: (bool, int)) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.setHandwheelOnOff(enable)
        return RECODE_FAILURE


    def set_z_calibrate(self, level: int = None) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_calibrate()
        return RECODE_FAILURE


    def set_z_calibrate_low_limit(self) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_calibrate_low_limit()
        return RECODE_FAILURE


    def set_z_calibrate_position(self) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_z_calibrate_position()
        return RECODE_FAILURE


    def set_align_position(self, target: (int, float)) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_align_position()
        return RECODE_FAILURE


    def getLAMPOnOFF(self) -> (int, int):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.getLAMPOnOFF()
        return RECODE_FAILURE, None


    def getAPBL(self) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.getAPBL()
        return RECODE_FAILURE, None


    def getLFBL(self) -> (int, float):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.getLFBL()
        return RECODE_FAILURE, None


    def changedLAMP(self, value: int, **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.changedLAMP(value, **args)
        return RECODE_FAILURE


    def changedLFBL(self, value: int, **args):
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.changedLFBL(value, **args)
        return RECODE_FAILURE


    def changedAPBL(self, value: int, **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.changedAPBL(value, **args)
        return RECODE_FAILURE


    def set_apbl(self, value: (int, float), **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_apbl(value, **args)
        return RECODE_FAILURE


    def set_lfbl(self, value: (int, float), **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_lfbl(value, **args)
        return RECODE_FAILURE


    def set_lamp(self, value: (int, float), **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_lamp(value, **args)
        return RECODE_FAILURE


    def set_lamp_enable(self, enable: (bool, int), **args) -> int:
        if not self.hasManager:
            self.initManager()

        if self.hasManager:
            return self.manager.set_lamp_enable(enable, **args)
        return RECODE_FAILURE


    def get_lamp_enable(self, **args) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_lamp_enable(**args)
        return RECODE_FAILURE


    def get_apbl(self, **args) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_apbl(**args)
        return RECODE_FAILURE, None


    def get_lfbl(self, **args) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_lfbl(**args)
        return RECODE_FAILURE, None


    def get_lamp(self, **args) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_lamp(**args)
        return RECODE_FAILURE, None


    def set_tl_rl_switch(self, enable: (int, bool), **args):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_tl_rl_switch(enable, **args)
        return RECODE_FAILURE


    def init_device_z(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.init_device_z()
        return RECODE_FAILURE


    def init_apbl(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.init_apbl()
        return RECODE_FAILURE


    def init_lfbl(self):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.init_lfbl()
        return RECODE_FAILURE


    def get_init_status(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_init_status()
        return RECODE_FAILURE


    def get_tl_rl_switch(self) -> (int, int):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_tl_rl_switch()
        return RECODE_FAILURE, None


    def set_current_position_low_limit(self) -> int:
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.set_current_position_low_limit()
        return RECODE_FAILURE


    def get_step_count(self) -> (int, float):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_step_count()
        return RECODE_FAILURE, None


    def get_min_acceleration(self) -> (int, float):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_min_acceleration()
        return RECODE_FAILURE, None


    def get_max_acceleration(self) -> (int, float):
        if not self.hasManager:
            self.initManager()
        if self.hasManager:
            return self.manager.get_max_acceleration()
        return RECODE_FAILURE, None


