#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：LMicroscopeImpl.py
@Description：
@Author：XSH
@Time：2025/12/8 20:02
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5                                          import Qt
from AppInterfaces.ImplInterfaces                   import LMicroscopeInterface
from AppContexts.Contexts                           import SerialContext, LeiCaContext, MicroscopeContext
from AppInterfaces.utils                            import *
from AppUtils.utils                                 import *
from AppCore.Levels                                 import *
from AppCore.Requests                               import *
from AppSettings.Settings                           import (RECODE_FAILURE, RECODE_SUCCEED)
from AppUtils.SerialPortUtil                        import SerialPortUtil
from AppCore.DBModels                               import ObjectiveModel, FocusingConfigModel
class MicroscopeID:
    SET_LED_EVENT                         : int = 77003                             #
    SET_FIELD_TL_EVENT                    : int = 83003                             #
    SET_TL_EVENT                          : int = 84003                             #
    SET_Z_EVENT                           : int = 71003                             #
    SET_OBJ_EVENT                         : int = 76003                             #
    SET_MASTER_EVENT                      : int = 70003                             #
    CHECK_PROG                            : int = 70008                             #
    SET_TO_DEFAULT                        : int = 70018                             #
    GET_CONFIG_MODE                       : int = 70074                             #
    SET_CONFIG_MODE                       : int = 70075                             #
    GET_INIT_STATUS                       : int = 70080                             #
    GET_OBJECTIVE_STATUS                  : int = 76004                             #
    SET_OBJ_POS_ABS_OBJ                   : int = 76022                             #
    GET_OBJ_POS_ABS_OBJ                   : int = 76023                             #
    REL_OBJ_POS_ABS_OBJ                   : int = 76024                             #
    SET_OBJ_MODE                          : int = 76025                             #
    GET_OBJ_MODE                          : int = 76026                             #
    SET_OBJ_IMM_DRY                       : int = 76027                             #
    GET_OBJ_IMM_DRY                       : int = 76028                             #
    SET_OBJ_DIP                           : int = 76040                             #
    SET_OBJ_PATHO_MODE                    : int = 76046                             #
    GET_OBJ_PATHO_MODE                    : int = 76047                             #
    SET_OBJPAR                            : int = 76032                             #
    GET_OBJPAR                            : int = 76033                             #
    SET_POS_ABS_LAMP                      : int = 77020                             #
    GET_POS_ABS_LAMP                      : int = 77021                             #
    SET_LAMP_TL_RL                        : int = 77025                             #
    GET_LAMP_TL_RL                        : int = 77026                             #
    SET_SHUTTER_LAMP                      : int = 77032                             #
    GET_SHUTTER_LAMP                      : int = 77033                             #
    INIT_LFBL_TL                          : int = 83020                             #
    INIT_APBL_TL                          : int = 84020                             #
    SET_POS_ABS_LFBL_TL                   : int = 83022                             #
    GET_POS_ABS_LFBL_TL                   : int = 83023                             #
    POS_MAX_TL_DIAPH1                     : int = 83029                             #
    SET_POS_ABS_APBL_TL                   : int = 84022                             #
    GET_POS_ABS_APBL_TL                   : int = 84023                             #
    POS_MAX_TL_DIAPH2                     : int = 84029                             #
    SET_MAN_ON_OFF                        : int = 71005                             #
    GET_STATUS                            : int = 71004                             #
    GET_MAN_ON_OFF                        : int = 71006                             #
    RESET_Z__UNIT                         : int = 71007                             #
    CHECK_Z__UNIT                         : int = 71008                             #
    INIT_Z                                : int = 71020                             #
    BREAK_Z                               : int = 71021                             #
    SET_POS_ABS_Z                         : int = 71022                             #
    GET_POS_ABS_Z                         : int = 71023                             #
    SET_POS_REL_Z                         : int = 71024                             #
    POS_CONST_Z                           : int = 71025                             #
    SET_LOW_LIMIT_Z                       : int = 71026                             #
    SET_FOCUS_Z                           : int = 71027                             #
    GET_LOW_LIMIT_Z                       : int = 71028                             #
    GET_FOCUS_Z                           : int = 71029                             #
    SET_ACCELERATION_Z                    : int = 71030                             #
    GET_ACCELERATION_Z                    : int = 71031                             #
    SET_SPEED_Z                           : int = 71032                             #
    GET_SPEED_Z                           : int = 71033                             #
    SET_FOCUS_POSITION                    : int = 71034                             #
    SET_FOCUS_LIMIT_ACTIVE                : int = 71053                             #
    GET_FOCUS_LIMIT_ACTIVE                : int = 71054                             #
    MOVE_TO_LOW_LIMIT_Z                   : int = 71035                             #
    SET_LOW_LIMIT_POSITION                : int = 71037                             #
    GET_STEP_COUNT                        : int = 71042                             #
    INIT_RANGE_Z                          : int = 71044                             #
    GET_ACCELERATION_MIN_Z                : int = 71048                             #
    GET_ACCELERATION_MAX_Z                : int = 71049                             #
    SET_Z_STEP_MODE                       : int = 71050                             #
    GET_Z_STEP_MODE                       : int = 71051                             #
    SET_UPPER_LIMIT                       : int = 71055                             #
    GET_UPPER_LIMIT                       : int = 71056                             #
    SET_SPOTLIGHT                         : int = 81022                             #
    GET_SPOTLIGHT                         : int = 81023                             #
MAX_SERIAL_DEFAULT_WAIT_TIMES   : int = 1500
MAX_SERIAL_READ_DELAY           : int = 5
MAX_SERIAL_SEND_BUFFER_LENGTH   : int = 255

class LMicroscopeImpl(Qt.QObject, LMicroscopeInterface):
    Locker: Qt.QMutex = Qt.QMutex()

    @classmethod
    def GetInstance(cls, *args, **kwargs) -> 'LMicroscopeImpl':
        return super(LMicroscopeImpl, cls).GetInstance(*args, **kwargs)


    def initContext(self):
        from AppSettings.AppSetting import AppSetting, AppConfig
        if not self.hasParameter:
            self.Parameter = LeiCaContext()
            try:
                self.Parameter.deserialize(AppConfig.LeiCaMicroscope.serialize())
            except Exception as e:
                AppUtils.print_Exception(e)

    def initManager(self, context = None, **args):
        self.initContext()
        if not self.hasManager:
            try:
                filename: str = self.Parameter.absoluteFilePath
                info: Qt.QFileInfo = Qt.QFileInfo(filename)
                if not info.exists() or not Qt.QLibrary.isLibrary(info.absoluteFilePath()):
                    return
                sys.path.append(info.absolutePath())
                clr.AddReference(info.absoluteFilePath())
                clr.AddReference('System')
                from ILeiCaMicroscope import IMicController, IMicroscope, LeiCaMicReader, MicController
                self.Controller: IMicController = MicController.GetInstance()
                self.Manager: IMicroscope = LeiCaMicReader.GetInstance()
                self.Manager.setParameter(self.Parameter.COM, self.Parameter.BaudRate, self.Parameter.DataBit, self.Parameter.StopBit, self.Parameter.ParityBit)
            except Exception as e:
                self.Manager = None
                AppUtils.print_Exception(e)
    def deleManager(self):
        try:
            if self.hasManager:
                self.Close()
                self.Manager.Dispose()
        except Exception as e:
            AppUtils.print_Exception(e)
        self.Parameter = None
        self.Manager = None
        gc.collect()

    def __init__(self, parent: Qt.QObject = None):
        super(LMicroscopeImpl, self).__init__(parent=parent)
        self.Initialization("LMicroscopeImpl", self, parent)

    def initValue(self):
        super(LMicroscopeImpl, self).initValue()
        self.initManager()

    def deleValue(self):
        super(LMicroscopeImpl, self).deleValue()
        self.Close()
        self.deleManager()
        gc.collect()


    def Open(self, timeOut: int = 1000, **args) -> int:
        self.initContext()
        if not self.isValid:
            self.initManager()
        if not self.isValid:
            return RECODE_FAILURE
        if self.IsOpen:
            self.Close()

        self.Parameter.IsOpen = False
        try:
            if not self.isValid:
                self.initManager()
            self.Manager.setParameter(self.Parameter.COM, self.Parameter.BaudRate, self.Parameter.DataBit,
                                      self.Parameter.StopBit, self.Parameter.ParityBit)
            self.Manager.Open()
            self.Parameter.IsOpen = self.Manager.IsOpen
        except Exception as e:
            AppUtils.print_Exception(e)

        return RECODE_SUCCEED if self.Parameter.IsOpen else RECODE_FAILURE

    def Close(self, timeOut: int = 1000, **args) -> int:
        self.initContext()
        if not self.isValid:
            self.initManager()
        try:
            if self.hasManager:
                self.Manager.Close()
                self.Manager.Dispose()
            self.Parameter.IsOpen = self.hasManager and self.Manager.IsOpen
        except Exception as e:
            AppUtils.print_Exception(e)
        return RECODE_SUCCEED if not self.Parameter.IsOpen else RECODE_FAILURE

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

    def isEqual(self, other) -> bool:
        if isinstance(other, MicroscopeImpl):
            return self.Manager == other.Manager
        return False

    def initMicroscopeEvent(self):
        isWrong: int
        isInit: int
        isWrong, isInit = self.getMasterFirmwareStatus()
        if RECODE_SUCCEED == isWrong and isInit:
            self.setZDriverMoveMode(True)
            self.setMasterEvents()
            self.setLampEvents()
            self.setAPBLEvents()
            self.setLFBLEvents()
            self.setObjectiveEvents()
            self.setSpotLightEvents()
            self.setDocuPortEvents()
            self.setZDriveEvents()

    def initMicroscopeObjective(self):
        isWrong: int
        isInit: int
        isWrong, isInit = self.getMasterFirmwareStatus()
        if RECODE_SUCCEED == isWrong and isInit:
            self.changed_spot_light(False)
            Wrong_Objective1: int
            Wrong_Objective10: int
            Wrong_Objective20: int
            Wrong_Objective40: int
            Wrong_Objective63: int
            Wrong_Objective100: int
            Wrong_ObjectiveNone: int
            Objective1: int
            Objective10: int
            Objective20: int
            Objective40: int
            Objective63: int
            Objective100: int
            ObjectiveNone: int
            _Objective1: int = ObjectiveLevel.toParameters().get(ObjectiveLevel.Objective1)
            _Objective10: int = ObjectiveLevel.toParameters().get(ObjectiveLevel.Objective10)
            _Objective20: int = ObjectiveLevel.toParameters().get(ObjectiveLevel.Objective20)
            _Objective40: int = ObjectiveLevel.toParameters().get(ObjectiveLevel.Objective40)
            _Objective63: int = ObjectiveLevel.toParameters().get(ObjectiveLevel.Objective63)
            _Objective100: int = ObjectiveLevel.toParameters().get(ObjectiveLevel.Objective100)
            _ObjectiveNone: int = ObjectiveLevel.toParameters().get(ObjectiveLevel.ObjectiveNone)

            Objective1, Wrong_Objective1 = self.GET_OBJPAR(ObjectiveLevel.Objective1)
            Objective10, Wrong_Objective10 = self.GET_OBJPAR(ObjectiveLevel.Objective10)
            Objective20, Wrong_Objective20 = self.GET_OBJPAR(ObjectiveLevel.Objective20)
            Objective40, Wrong_Objective40 = self.GET_OBJPAR(ObjectiveLevel.Objective40)
            Objective63, Wrong_Objective63 = self.GET_OBJPAR(ObjectiveLevel.Objective63)
            Objective100, Wrong_Objective100 = self.GET_OBJPAR(ObjectiveLevel.Objective100)
            ObjectiveNone, Wrong_ObjectiveNone = self.GET_OBJPAR(ObjectiveLevel.ObjectiveNone)
            if RECODE_SUCCEED != Wrong_Objective1 or Objective1 != _Objective1:
                self.SET_OBJPAR(ObjectiveLevel.Objective1)
            if RECODE_SUCCEED != Wrong_Objective10 or Objective10 != _Objective10:
                self.SET_OBJPAR(ObjectiveLevel.Objective10)
            if RECODE_SUCCEED != Wrong_Objective20 or Objective20 != _Objective20:
                self.SET_OBJPAR(ObjectiveLevel.Objective20)
            if RECODE_SUCCEED != Wrong_Objective40 or Objective40 != _Objective40:
                self.SET_OBJPAR(ObjectiveLevel.Objective40)
            if RECODE_SUCCEED != Wrong_Objective63 or Objective63 != _Objective63:
                self.SET_OBJPAR(ObjectiveLevel.Objective63)
            if RECODE_SUCCEED != Wrong_Objective100 or Objective100 != _Objective100:
                self.SET_OBJPAR(ObjectiveLevel.Objective100)
            if RECODE_SUCCEED != Wrong_ObjectiveNone or ObjectiveNone != _ObjectiveNone:
                self.SET_OBJPAR(ObjectiveLevel.ObjectiveNone)
            Objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(ObjectiveLevel.Objective1)
            self.set_z_speed(Objective.Default_Speed)
            self.set_z_range(Objective.Lower_Limit, Objective.Upper_Limit)
            self.changedObjective(ObjectiveLevel.Objective1)

    def initZDriver(self):
        isWrong: int
        isInit: int
        isWrong, isInit = self.getMasterFirmwareStatus()
        if RECODE_SUCCEED == isWrong and isInit:
            Objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(ObjectiveLevel.Objective1)
            self.SET_Z_STEP_MODE(1)
            self.BREAK_Z()
            self.isMoving = False
            self.set_z_speed(Objective.Default_Speed)
            self.SET_LOWER_LIMIT(Objective.Lower_Limit)
            self.SET_UPPER_LIMIT(Objective.Upper_Limit)
            self.isMoving = True
            self.INIT_Z()
            self.waitmove_finish(Objective.Lower_Limit)
            self.BREAK_Z()
            self.isMoving = False
            self.SET_Z_EVENT()

    def initMicroscopeZDrive(self):
        isWrong: int
        isInit: int
        isWrong, isInit = self.getMasterFirmwareStatus()
        if RECODE_SUCCEED == isWrong and isInit:

            Objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(ObjectiveLevel.Objective1)
            self.SET_Z_STEP_MODE(1)
            self.BREAK_Z()
            self.isMoving = False
            self.set_z_speed(Objective.Default_Speed)
            self.SET_LOWER_LIMIT(Objective.Lower_Limit)
            self.SET_UPPER_LIMIT(Objective.Upper_Limit)
            self.waitmove(Objective.Lower_Limit)
            self.isMoving = True
            self.INIT_Z()
            self.waitmove_finish(Objective.Lower_Limit)
            self.BREAK_Z()
            self.isMoving = False
            position: int
            _warning: int
            _warning, position = self.get_position()
            if _warning == RECODE_SUCCEED and position > Objective.Lower_Limit:
                self.waitmove(Objective.Lower_Limit)

            _warning, position = self.get_position()
            if _warning == RECODE_SUCCEED and position > Objective.Lower_Limit:
                self.waitmove(Objective.Lower_Limit)

            self.SET_Z_EVENT()

    def initMicroscopeLight(self):
        isWrong: int
        isInit: int
        isWrong, isInit = self.getMasterFirmwareStatus()
        if RECODE_SUCCEED == isWrong and isInit:
            self.SET_SHUTTER_LAMP(True)
            self.SET_MIN_POS_ABS_LAMP()
            self.SET_MIN_POS_ABS_LFBL_TL()
            self.SET_MIN_POS_ABS_APBL_TL()

    def initMicroscope(self):
        self.setMasterConfigMode(False)
        self.initMicroscopeEvent()
        self.initMicroscopeLight()
        self.initMicroscopeZDrive()
        self.initMicroscopeObjective()
        self.initMicroscopeEvent()

    def move_to_z_lower_limit(self) -> int:
        self.set_z_move_mode(1)
        Objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(ObjectiveLevel.Objective1)
        self.set_z_speed(Objective.Default_Speed)
        self.set_z_range(Objective.Lower_Limit, Objective.Upper_Limit)
        return self.waitmove(Objective.Lower_Limit)

    def openTL(self):
        return self.SET_SHUTTER_LAMP(True)

    def closeTL(self):
        return self.SET_SHUTTER_LAMP(False)

    def IsTLOpen(self) -> bool:
        isWrong: int
        enable: int
        isWrong, enable = self.GET_SHUTTER_LAMP()
        return isWrong == RECODE_SUCCEED and enable == 1

    def home(self) -> int:
        self.initMicroscope()
        isWrong: int = self.GET_INIT_STATUS()
        self._IsInitialize = RECODE_SUCCEED == isWrong
        return isWrong

    def waithome(self) -> int:
        return self.home()

    def move(self, position: (int, float), mode: int = 1, **args) -> int:

        isWrong = self.SET_POS_ABS_Z(int(round(float(position), 0)))
        return isWrong

    def stop_move(self) -> int:
        return self.BREAK_Z()

    def rel_move(self, value: (int, float), mode: int = 1, **args) -> int:
        return self.SET_POS_REL_Z(value)

    def waitmove(self, position: (int, float), mode: int = 1, **args) -> int:
        _position: int
        _target: int = abs(int(round(float(position), 0)))
        isWrong: int
        self.isMoving = True
        isWrong = self.SET_POS_ABS_Z(_target)
        endtime: Qt.QDateTime = Qt.QDateTime.currentDateTime().addMSecs(1000)
        while True:
            if RECODE_SUCCEED == isWrong or Qt.QDateTime.currentDateTime() > endtime:
                break
            isWrong = self.SET_POS_ABS_Z(_target)
        # isWrong = self.waitmove_complete(_target)
        self.isMoving = False
        return isWrong

    def waitingToStop(self) -> int:
        isWrong: int = RECODE_FAILURE
        endtime: Qt.QDateTime = Qt.QDateTime.currentDateTime().addMSecs(360000)
        waitdelay: int = 10
        while True:
            isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
            if RECODE_SUCCEED == isWrong:
                if isinstance(Moving, int) and not Moving:
                    break
                if isinstance(Lower, int) and Lower:
                    break
                if isinstance(Upper, int) and Upper:
                    break
                if isinstance(Limit, int) and Limit:
                    break
                if isinstance(Focus, int) and Focus:
                    break
            if Qt.QDateTime.currentDateTime() > endtime:
                break
            AppTimeLoop.processEvents(waitdelay)
        self.BREAK_Z()
        return RECODE_SUCCEED


    def isMoveRange(self) -> (int, int):
        isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
        return isWrong, Limit

    def isMoveLower(self) -> (int, int):
        isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
        return isWrong, Lower

    def isMoveUpper(self) -> (int, int):
        isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
        return isWrong, Upper

    def isMoveFocus(self) -> (int, int):
        isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
        return isWrong, Focus

    def isMoveMoving(self) -> (int, int):
        isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
        return isWrong, Moving


    def check_z(self):
        return self.getZDriverFirmwareStatus()


    def reset_z(self) -> int:
        return self.setZDriverReset()


    def is_moving(self) -> int:
        isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
        return isWrong, Moving


    def get_move_status(self) -> (int, int):
        isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
        status: int = 1
        if RECODE_SUCCEED == isWrong:
            if isinstance(Moving, int) and Moving == 0:
                status = 0
            elif isinstance(Lower, int) and Lower:
                status = 0
            elif isinstance(Upper, int) and Upper:
                status = 0
            elif isinstance(Limit, int) and Limit:
                status = 0
            elif isinstance(Focus, int) and Focus:
                status = 0
            
        return isWrong, status
    
    @property
    def hasMoving(self) -> bool:
        return hasattr(self, 'isMoving') and isinstance(self.isMoving, (bool, int))

    def waitmove_complete(self, position: (int, float), **args) -> int:
        _position: int
        _target: int = abs(int(round(float(position), 0)))
        endtime: Qt.QDateTime = Qt.QDateTime.currentDateTime().addMSecs(360000)
        waitdelay: int = 5
        isWrong, _position = self.GET_POS_ABS_Z()
        isWrong: int = RECODE_FAILURE
        Moving: int
        Lower: int
        Upper: int
        Limit: int
        Focus: int
        while True:
            try:
                if int(_position) == int(_target) and RECODE_SUCCEED == isWrong:
                    break
            except Exception as e:
                pass
            isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
            if RECODE_SUCCEED == isWrong:
                if isinstance(Moving, int) and Moving == 0:
                    break
                if isinstance(Lower, int) and Lower:
                    break
                if isinstance(Upper, int) and Upper:
                    break
                if isinstance(Limit, int) and Limit:
                    break
                if isinstance(Focus, int) and Focus:
                    break
            if Qt.QDateTime.currentDateTime() > endtime:
                break
            isWrong, _position = self.GET_POS_ABS_Z()
            try:
                if RECODE_SUCCEED == isWrong and int(_position) == int(_target):
                    break
            except Exception as e:
                pass
            AppTimeLoop.delay(waitdelay)
        self.BREAK_Z()
        return isWrong

    def waitmove_finish(self, position: (int, float), **args) -> int:
        _position: int
        _target: int = int(round(float(position), 0))
        isWrong, _position = self.GET_POS_ABS_Z()
        endtime: Qt.QDateTime = Qt.QDateTime.currentDateTime().addMSecs(360000)
        waitdelay: int = 10
        while _position != _target:
            isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
            if RECODE_SUCCEED == isWrong:
                if isinstance(Moving, int) and Moving == 0:
                    break
                if isinstance(Lower, int) and Lower:
                    break
                if isinstance(Upper, int) and Upper:
                    break
                if isinstance(Limit, int) and Limit:
                    break
                if isinstance(Focus, int) and Focus:
                    break

            if Qt.QDateTime.currentDateTime() > endtime:
                break
            isWrong, _position = self.GET_POS_ABS_Z()
            try:
                if int(_position) == int(_target):
                    break
            except Exception as e:
                pass
            AppTimeLoop.processEvents(waitdelay)
        self.BREAK_Z()
        self.isMoving = False
        return RECODE_SUCCEED

    def waitmove_lower_limit(self):
        self.setZDriverConstPosition(-(self.MAX_Z_SPEED // 2))
        self.waitingToStop()

        return RECODE_SUCCEED

    def waitmove_upper_limit(self) -> int:
        return self.waitmove(self.MAX_Z_POSITION)





    def waitmove_h_lower_limit(self, **args) -> int:
        return self.waitmove_lower_limit()


    def waitmove_h_upper_limit(self, **args) -> int:
        isWrong, low_limit = self.GET_UPPER_LIMIT()
        self.SET_Z_STEP_MODE(1)
        self.waitmove(low_limit if isinstance(low_limit, (float, int)) and low_limit > 0 else self.MAX_Z_POSITION)
        return RECODE_SUCCEED

    
    def get_z_status(self) -> (int, int, int, int, int, int):
        isWrong, Moving, Lower, Upper, Limit, Focus = self.ZDriverMoveStatus()
        return isWrong, Moving, Lower, Upper, Limit, Focus


    def set_focus_position(self, position: (int, float)) -> int:
        return self.setZDriverFocusLimit(position)


    def set_focus_limit_active(self, enable: (int, bool)) -> int:
        return self.setZDriverFocusLimitEnable(enable)

    def get_focus_limit_active(self) -> (int, int):
        return self.getZDriverFocusLimitEnable()


    def is_h_lower_limit(self) -> int:
        isWrong, low_limit = self.GET_LOW_LIMIT_Z()
        if RECODE_SUCCEED == isWrong:
            isWrong, _position = self.GET_POS_ABS_Z()
            if RECODE_SUCCEED == isWrong:
                if low_limit < 0:
                    return _position == 0
                return 1 if _position <= low_limit else 0
        return 0


    def is_h_upper_limit(self) -> int:
        isWrong, low_limit = self.GET_UPPER_LIMIT()
        if RECODE_SUCCEED == isWrong:
            isWrong, _position = self.GET_POS_ABS_Z()
            if RECODE_SUCCEED == isWrong:
                if low_limit < 0:
                    return _position == 0
                return 1 if _position >= low_limit else 0
        return 0

    
    def is_s_lower_limit(self) -> int:
        isWrong, low_limit = self.GET_LOW_LIMIT_Z()
        if RECODE_SUCCEED == isWrong:
            isWrong, _position = self.GET_POS_ABS_Z()
            if RECODE_SUCCEED == isWrong:
                if low_limit < 0:
                    return _position == 0
                return 1 if _position <= low_limit else 0
        return 0


    def is_s_upper_limit(self) -> int:
        isWrong, low_limit = self.GET_UPPER_LIMIT()
        if RECODE_SUCCEED == isWrong:
            isWrong, _position = self.GET_POS_ABS_Z()
            if RECODE_SUCCEED == isWrong:
                if low_limit < 0:
                    return _position == 0
                return 1 if _position >= low_limit else 0
        return 0
    
    def getPosition(self) -> int:
        isWrong: int
        position: int
        isWrong, position = self.GET_POS_ABS_Z()
        return position

    def setFastSpeedMode(self):
        return self.SET_Z_STEP_MODE(1)

    def setNormalSpeedMode(self):
        return self.SET_Z_STEP_MODE(0)

    def changedObjective(self, level: int, is_lower_limit: bool = True, **args) -> int:
        self.BREAK_Z()
        isWrong = self.SET_OBJ_POS_ABS_OBJ(level)
        endtime: Qt.QDateTime = Qt.QDateTime.currentDateTime().addMSecs(360000)
        waitdelay: int = 100
        while True:
            if RECODE_SUCCEED == isWrong:
                break
            if Qt.QDateTime.currentDateTime() > endtime:
                break
            AppTimeLoop.delay(waitdelay)
        self.changedLightIntensity(level)
        self.setObjectiveDIP()

        return isWrong


    def set_objective_position(self, position: (int, float)) -> int:
        return self.setObjectiveAbsPosition(position)
    
    def changedLightIntensity(self, level: int, **args) -> int:
        isWrong: int
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        self.SET_SHUTTER_LAMP(True)
        self.SET_POS_ABS_LAMP(objective.LAMP)
        self.SET_POS_ABS_APBL_TL(objective.APBL)
        self.SET_POS_ABS_LFBL_TL(objective.LFBL)
        return RECODE_SUCCEED

    def waitmove_safe(self, level) -> int:
        isWrong: int
        position: int
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        isWrong = self.waitmove(objective.Safe_Limit)
        return isWrong

    def get_objective_safe_limit(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.Safe_Limit

    def get_objective_lower_limit(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.Lower_Limit

    def get_objective_upper_limit(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.Upper_Limit

    def get_objective_focus_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.Focus_Speed

    def get_objective_first_focus_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.First_Focus_Speed

    def get_objective_second_focus_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.Second_Focus_Speed

    def get_objective_three_focus_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.Three_Focus_Speed

    def get_objective_default_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.Default_Speed

    def get_objective_scan_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return objective.Scan_Speed

    def set_z_upper_limit(self, limit=-1) -> int:
        return self.SET_UPPER_LIMIT(int(limit))

    def set_z_lower_limit(self, limit=-1) -> int:
        return self.SET_LOW_LIMIT_Z(int(limit))

    def set_z_range(self, min_limit: int = -1, max_limit: int = -1) -> int:
        self.SET_LOW_LIMIT_Z(min_limit)
        self.SET_UPPER_LIMIT(max_limit)
        return RECODE_SUCCEED

    def set_z_speed(self, speed: (float, int)):
        return self.SET_SPEED_Z(speed)

    def set_z_move_mode(self, enable: (int, bool)):
        return self.SET_Z_STEP_MODE(1 if isinstance(enable, (int, bool)) and enable else 0)

    def set_objective_upper_limit(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return self.SET_UPPER_LIMIT(int(objective.Upper_Limit))

    def set_objective_limit(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        self.SET_LOW_LIMIT_Z(int(objective.Lower_Limit))
        self.SET_UPPER_LIMIT(int(objective.Upper_Limit))
        self.SET_SPEED_Z(int(objective.Default_Speed))
        self.SET_Z_STEP_MODE(1)
        return RECODE_SUCCEED

    def set_objective_lower_limit(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return self.SET_LOW_LIMIT_Z(int(objective.Lower_Limit))

    def set_objective_focus_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return self.SET_SPEED_Z(objective.Focus_Speed)

    def set_objective_default_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return self.SET_SPEED_Z(objective.Default_Speed)

    def set_objective_scan_speed(self, level) -> int:
        objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        return self.SET_SPEED_Z(objective.Scan_Speed)

    def set_upper_limit(self, position: (int, float)) -> int:
        return self.SET_UPPER_LIMIT(int(position))

    def set_lower_limit(self, position: (int, float)) -> int:
        return self.SET_LOW_LIMIT_Z(int(position))

    def get_position(self) -> (int, int):
        isWrong: int
        position: int
        isWrong, position = self.GET_POS_ABS_Z()
        return isWrong, position

    def getObjective(self) -> int:
        isWrong: int
        position: int
        isWrong, position = self.GET_OBJ_POS_ABS_OBJ()
        return position

    def get_objective(self) -> (int, int):
        isWrong: int
        position: int
        return self.GET_OBJ_POS_ABS_OBJ()


    def get_objective_status(self) -> (int, int):
        return self.getObjectiveStatus()


    def set_objective_mode(self, mode: int) -> int:
        return self.setObjectiveOperationMode(mode)


    def get_objective_mode(self) -> (int, int):
        return self.getObjectiveDryMode()


    def set_objective_dry(self, dry: str) -> int:
        return self.setObjectiveDRYMode( f'{dry}')


    def get_objective_dry(self) -> (int, int):
        raise Exception('Interface Instance error')


    def set_objective_dip(self) -> int:
        return self.setObjectiveDIP()


    def set_objective_patho_mode(self, mode: int = 0) -> int:
        return self.setObjectivePathoMode(mode)


    def get_objective_patho_mode(self) -> (int, int):
        return self.getObjectivePathoMode()


    def get_objective_position(self) -> (int, int):
        return self.getObjectiveAbsPosition()

    def currentObjective(self) -> (int, int):
        isWrong: int
        objective: int
        isWrong, objective = self.GET_OBJ_POS_ABS_OBJ()
        return isWrong, objective

    def SET_MASTER_EVENT(self):
        isWrong: int = self.ChangedMasterEvents([0, 0, 0, 0, 0, 0, 0, 0])
        return isWrong == RECODE_SUCCEED

    def SET_OBJ_EVENT(self):
        isWrong: int = self.ChangedObjectiveEvents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        return isWrong == RECODE_SUCCEED

    def SET_LAMP_EVENT(self):
        isWrong: int = self.ChangedLampEvents([0, 0, 0, 0, 0, 0, 0])
        return isWrong == RECODE_SUCCEED

    def SET_Z_EVENT(self):
        isWrong: int = self.ChangedZDriveEvents([0, 0, 0, 0, 0, 0, 0, 0, 0])
        return isWrong == RECODE_SUCCEED

    def SET_TL_EVENT(self):
        isWrong: int = self.ChangedAPBLEvents([0, 0])
        return isWrong == RECODE_SUCCEED

    def SET_FIELD_TL_EVENT(self):
        isWrong: int = self.ChangedLFBLEvents([0, 0])
        return isWrong == RECODE_SUCCEED

    def SET_LED_EVENT(self):
        isWrong: int = self.ChangedLampEvents([0, 0, 0, 0])
        return isWrong == RECODE_SUCCEED

    def set_SPOTLIGHT_EVENT(self):
        isWrong: int = self.ChangedSpotLightEvents([0, 0, 0])
        return isWrong == RECODE_SUCCEED

    def CHECK_PROG(self) -> bool:
        """返回固件状态 0 = 固件正在从引导扇区运行 1 = 固件正在从程序内存运行"""
        isWrong, Status = self.getMasterFirmwareStatus()
        return isWrong == RECODE_SUCCEED and Status

    def SET_TO_DEFAULT(self):
        """个显微镜重置为出厂默认设置"""
        isWrong: int = self.setMasterDefault()
        return isWrong

    def SET_CONFIG_MODE(self, enable: (int, bool) = 0):
        """设置配置模式 0: 配置模式关闭 1：配置模式开启"""
        isWrong: int = self.setMasterConfigMode(True if isinstance(enable, (bool, int)) and enable else False)
        return isWrong

    def GET_CONFIG_MODE(self):
        """设置配置模式 0: 配置模式关闭 1：配置模式开启"""
        isWrong, Status = self.getMasterConfigMode()
        return isWrong

    def GET_INIT_STATUS(self) -> int:
        """70080 获取初始化状态 0: 硬件初始化未完成 1：硬件初始化完成"""
        isWrong, status = self.getMicroscopeInitStatus()

        return RECODE_SUCCEED == isWrong and status

    def INIT_OBJPAR(self) -> int:
        isWrong: int = self.SET_OBJPAR(ObjectiveLevel.Objective1)
        return isWrong

    def SET_OBJPAR(self, level: int) -> int:
        Objective: ObjectiveModel = ObjectiveModel.getObjectiveConfig(level)
        parameters: list = [
            (1, ObjectiveLevel.toParameters().get(level)),
            (10, Objective.LFBL),  # 设置放大倍率
            (11, Objective.APBL),  # 设置视场光阑值
            (14, Objective.LAMP),  # 设置孔径光阑值
        ]
        for parameter in parameters:
            self.setObjectiveMethodParameter(Objective.Level, [f'{item}' for item in parameter])
        return RECODE_SUCCEED

    def GET_OBJPAR(self, level: int) -> (int, int):
        isWrong: int
        Status: int
        isWrong, Status = self.getObjectiveMethodParameter(level, 1)
        return isWrong, Status

    def SET_OBJ_POS_ABS_OBJ(self, level: int) -> int:
        isWrong: int = self.setObjectiveAbsPosition(level)
        return isWrong

    def GET_OBJ_POS_ABS_OBJ(self) -> (int, int):
        isWrong: int
        Status: int
        isWrong, Status = self.getObjectiveAbsPosition()
        if RECODE_SUCCEED != isWrong or not isinstance(Status, int):
            return RECODE_FAILURE, ObjectiveLevel.Objective1
        return isWrong, Status

    def SET_POS_ABS_LAMP(self, intensity: int) -> int:
        isWrong: int = self.setLampAbsPosition(intensity)
        return isWrong

    def SET_MAX_POS_ABS_LAMP(self) -> int:
        isWrong: int = self.setLampAbsPosition(255)
        return isWrong

    def SET_MIN_POS_ABS_LAMP(self) -> int:
        isWrong: int = self.setLampAbsPosition(1)
        return isWrong

    def GET_POS_ABS_LAMP(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        ILStatus: int = None
        TLStatus: int = None
        isWrong, ILStatus, TLStatus = self.getLampAbsPosition()
        return isWrong, TLStatus

    def SET_SHUTTER_LAMP(self, enable: (bool, int)) -> int:
        isWrong: int = self.setLampOnOff(True if isinstance(enable, (bool, int)) and enable else False)
        return isWrong

    def GET_SHUTTER_LAMP(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        ILStatus: int = None
        TLStatus: int = None
        isWrong, ILStatus, TLStatus = self.getLampOnOff()
        return isWrong, TLStatus

    def INIT_LFBL_TL(self, enable: (bool, int) = 1) -> int:  # __INIT_LFBL_TL
        isWrong: int = self.setLFBLInit(True if isinstance(enable, (bool, int)) and enable else False)
        return isWrong

    def INIT_APBL_TL(self, enable: (bool, int) = 1) -> int:  # __INIT_APBL_TL
        isWrong: int = self.setAPBLInit(True if isinstance(enable, (bool, int)) and enable else False)
        return isWrong

    def SET_POS_ABS_LFBL_TL(self, value: int) -> int:
        """视场光阑 定位到指定的绝对值"""
        isWrong: int = self.setLFBLAbsPosition(value)
        return isWrong

    def SET_MAX_POS_ABS_LFBL_TL(self) -> int:
        """视场光阑最大位置"""
        isWrong: int = self.setLFBLAbsPosition(38)
        return isWrong

    def SET_MIN_POS_ABS_LFBL_TL(self) -> int:
        """视场光阑最大位置"""
        isWrong: int = self.setLFBLAbsPosition(1)
        return isWrong

    def POS_MAX_TL_DIAPH1(self) -> int:
        """定位至视场光阑最大光圈位置"""
        isWrong: int = self.LFBLToMaxPosition()
        return isWrong

    def GET_SPOTLIGHT(self) -> (int, int):
        isWrong: int
        Status: int
        isWrong, Status = self.getSpotLightStatus()
        return isWrong, Status

    def SET_SPOTLIGHT(self, enable: (bool, int)) -> int:
        isWrong: int = self.setSpotLight(True if isinstance(enable, (bool, int)) and enable else False)
        return isWrong

    def changed_spot_light(self, enable: (bool, int)) -> int:
        return self.setSpotLight(True if isinstance(enable, (bool, int)) and enable else False)

    def get_spot_light(self) -> (int, int):
        return self.getSpotLightStatus()

    def GET_POS_ABS_LFBL_TL(self) -> (int, int):
        """输出视场光阑的当前位置"""
        isWrong, Status = self.getLFBLAbsPosition()
        return isWrong, Status

    def SET_POS_ABS_APBL_TL(self, value: int) -> int:
        """孔径光阑 定位到指定的绝对值"""
        isWrong: int = self.setAPBLAbsPosition(value)
        return isWrong

    def GET_POS_ABS_APBL_TL(self) -> object:
        """输出孔径光阑的当前位置"""
        isWrong, Status = self.getAPBLAbsPosition()
        return Status

    def SET_MAX_POS_ABS_APBL_TL(self) -> int:
        """孔径光阑最大位置"""
        isWrong: int = self.APBLToMaxPosition()
        return isWrong

    def SET_MIN_POS_ABS_APBL_TL(self) -> int:
        """孔径光阑最大位置"""
        isWrong: int = self.setAPBLAbsPosition(1)
        return isWrong

    def POS_MAX_TL_DIAPH2(self) -> int:
        """定位至孔径光阑最大光圈位置"""
        isWrong: int = self.APBLToMaxPosition()
        return isWrong

    def SET_MAN_ON_OFF(self, enable: (bool, int) = True) -> int:
        """打开或关闭 Z-DRIVE 的手动操作"""
        isWrong: int = self.setZDriverManualOptionStatus(True if isinstance(enable, (bool, int)) and enable else False)
        return isWrong

    def GET_MAN_ON_OFF(self) -> (int, int):
        """返回 Z-DRIVE 的手动操作是否已打开或关闭"""
        isWrong, Status = self.getZDriverManualOptionStatus()
        return isWrong, Status

    def RESET_Z__UNIT(self) -> int:
        """
        此命令将 Z-DRIVE 的以下参数重置为默认值
        加速度参数
        速度参数
        软件限制
        焦点位置
        自动传递事件
        手动操作
        """
        isWrong: int = self.setZDriverReset()
        return isWrong

    def CHECK_Z__UNIT(self) -> int:
        """读取固件状态 0 = 固件正在从引导扇区运行 1 = 固件正在从程序内存运行"""
        isWrong, Status = self.getZDriverFirmwareStatus()
        return Status

    def INIT_Z(self) -> int:
        """初始化 Z-DRIVE Z-DRIVE 移动到下方硬件端开关并重置零点"""
        isWrong: int = self.setZDriverInit()
        return isWrong

    def INIT_RANGE_Z(self) -> int:
        isWrong: int = self.setZDriverLowerLimit(-1)
        if RECODE_SUCCEED == isWrong:
            isWrong = self.setZDriverUpperLimit(-1)
        return isWrong

    def BREAK_Z(self) -> int:
        """此命令将中止 Z-DRIVE 的当前定位 未完全执行的命令将通过 FLOW_ERR 进行确认 之后BREAK_Z 将退出"""
        isWrong: int = self.setZDriverBreak()
        return isWrong

    def ZDriverMoveStatus(self) -> (int, int, int, int, int, int):
        isWrong: int
        Moving: int
        Lower: int
        Upper: int
        Limit: int
        Focus: int
        isWrong, Moving, Lower, Upper, Limit, Focus = self.getZDriverStatus()
        return isWrong, Moving, Lower, Upper, Limit, Focus

    def SET_POS_ABS_Z(self, POS: (int, float)) -> int:
        """将功能单元定位到以微步（计数）为单位的给定绝对值 Z 范围 0 – 最大位置值"""
        if not isinstance(POS, (int, float)):
            return RECODE_FAILURE
        if int(POS) < 0:
            return RECODE_FAILURE
        isWrong: int = self.setZDriverAbsPosition(int(POS) if isinstance(POS, (int, float)) and POS >= 0 else 0)
        return isWrong

    def GET_POS_ABS_Z(self) -> (int, int):
        """以微步（计数）为单位读取功能单元的当前位置"""
        isWrong, Position = self.getZDriverAbsPosition()
        return isWrong, Position

    def SET_POS_REL_Z(self, POS: (int, float)) -> int:
        isWrong = self.setZDriverRelPosition(int(POS) if isinstance(POS, (int, float)) else 0)
        return isWrong

    def POS_CONST_Z(self, SPEED: int, target: int = None, **args) -> int:
        """以恒定速度移动到最大位置"""
        isWrong: int = RECODE_FAILURE
        if not isinstance(SPEED, (int, float)) or int(SPEED) <= 0:
            return isWrong
        for count in range(3):
            isWrong = self.setZDriverConstPosition(int(SPEED))
            AppTimeLoop.processGlobalEvents(200)
            if RECODE_SUCCEED == isWrong:
                isWrong, Moving, Lower, Upper, Limit, Focus = self.get_z_status()
                if RECODE_SUCCEED == isWrong and isinstance(Moving, (int, float)) and Moving:
                    break
                isWrong = RECODE_FAILURE
        return isWrong

    def SET_LOW_LIMIT_Z(self, value: int) -> int:
        """将下限阈值设置为给定的 Z 轴位置 值“0”位于下部机械限位开关。如果参数值设置为-1，则阈值将重置为其默认值"""
        return self.setZDriverLowerLimit(int(value))

    def SET_FOCUS_Z(self, value: int) -> int:
        """将焦点位置设置为指定的 Z 轴位置 如果参数值设置为 -1 ，则阈值将重置为其默认值。默认值： -1"""
        return self.setZDriverFocusLimit(int(value))

    def GET_LOW_LIMIT_Z(self) -> (int, int):
        isWrong, Status = self.getZDriverLowerLimit()
        return isWrong, Status

    def GET_FOCUS_Z(self) -> int:
        isWrong, Status = self.getZDriverFocusLimit()
        return isWrong, Status

    def GET_RAMP_Z(self) -> int:
        isWrong, ACCELERATION = self.getZDriverAcceleration()
        return isWrong, ACCELERATION

    def SET_SPEED_Z(self, SPEED: (float, int)) -> int:
        if not isinstance(SPEED, (int, float)) or int(SPEED) <= 0:
            return RECODE_FAILURE
        isWrong: int = self.setZDriverSpeed(int(SPEED))
        return isWrong

    def GET_SPEED_Z(self) -> int:
        isWrong, SPEED = self.getZDriverSpeed()
        return isWrong, SPEED

    def MOVE_TO_POS_FOCUS(self) -> int:
        isWrong: int = self.ZDriverMoveToFocusLimit()
        return isWrong

    def MOVE_TO_LOW_LIMIT_Z(self) -> int:
        isWrong: int = self.ZDriverMoveToLowerLimit()
        return isWrong

    def SET_Z_STEP_MODE(self, enable: (bool, int)) -> int:
        isWrong: int = self.setZDriverMoveMode(True if isinstance(enable, (bool, int)) and enable else False)
        return isWrong

    def GET_Z_STEP_MODE(self) -> (int, int):
        isWrong: int
        Status: int
        isWrong, Status = self.getZDriverMoveMode()
        return isWrong, Status

    def SET_UPPER_LIMIT(self, POS: int) -> int:
        isWrong = self.setZDriverUpperLimit(int(POS) if isinstance(POS, (int, float)) and int(POS) > 0 else -1)
        return isWrong

    def SET_LOWER_LIMIT(self, POS: int) -> int:
        isWrong = self.setZDriverLowerLimit(int(POS) if isinstance(POS, (int, float)) and int(POS) > 0 else -1)
        return isWrong

    def GET_LOWER_LIMIT(self) -> int:
        isWrong, Limit = self.getZDriverLowerLimit()
        return isWrong, Limit

    def GET_UPPER_LIMIT(self) -> int:
        isWrong, Limit = self.getZDriverUpperLimit()
        return isWrong, Limit

    def setDocuPortEvents(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setDocuPortEvents(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setMasterEvents(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setMasterEvents(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriveEvents(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriveEvents(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setObjectiveEvents(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setObjectiveEvents(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLampEvents(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampEvents(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setSpotLightEvents(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setSpotLightEvents(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLFBLEvents(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLFBLEvents(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setAPBLEvents(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setAPBLEvents(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ChangedDocuPortEvents(self, events: list[int]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            import System
            array = System.Array[System.Int32](events)
            isWrong = self.Controller.ChangedDocuPortEvents(self.Manager, array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ChangedMasterEvents(self, events: list[int]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            import System
            array = System.Array[System.Int32](events)
            isWrong = self.Controller.ChangedMasterEvents(self.Manager, array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ChangedZDriveEvents(self, events: list[int]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            import System
            array = System.Array[System.Int32](events)
            isWrong = self.Controller.ChangedZDriveEvents(self.Manager, array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ChangedObjectiveEvents(self, events: list[int]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            import System
            array = System.Array[System.Int32](events)
            isWrong = self.Controller.ChangedObjectiveEvents(self.Manager, array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ChangedLampEvents(self, events: list[int]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            import System
            array = System.Array[System.Int32](events)
            isWrong = self.Controller.ChangedLampEvents(self.Manager, array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ChangedSpotLightEvents(self, events: list[int]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            import System
            array = System.Array[System.Int32](events)
            isWrong = self.Controller.ChangedSpotLightEvents(self.Manager, array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ChangedLFBLEvents(self, events: list[int]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            import System
            array = System.Array[System.Int32](events)
            isWrong = self.Controller.ChangedLFBLEvents(self.Manager, array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ChangedAPBLEvents(self, events: list[int]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            import System
            array = System.Array[System.Int32](events)
            isWrong = self.Controller.ChangedAPBLEvents(self.Manager, array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setMasterReset(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setMasterReset(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setMasterDefault(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setMasterDefault(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setMasterConfigMode(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setMasterConfigMode(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setMasterWaitTimes(self, waittimes: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setMasterWaitTimes(self.Manager, waittimes)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setManualOptionStatus(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setManualOptionStatus(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def getMicroscopeInitStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getMicroscopeInitStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getMasterFirmwareStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getMasterFirmwareStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getMasterConfigMode(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getMasterConfigMode(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getManualOptionStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getManualOptionStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def setZDriverManualOptionStatus(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverManualOptionStatus(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverReset(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverReset(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverInit(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverInit(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverBreak(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverBreak(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverAbsPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverAbsPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverRelPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverRelPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverConstPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverConstPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverLowerLimit(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverLowerLimit(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverFocusLimit(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverFocusLimit(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverUpperLimit(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverUpperLimit(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverAcceleration(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverAcceleration(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverSpeed(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverSpeed(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ZDriverMoveToFocusLimit(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.ZDriverMoveToFocusLimit(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ZDriverMoveToLowerLimit(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.ZDriverMoveToLowerLimit(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ZDriverPositionAsFocus(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.ZDriverPositionAsFocus(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ZDriverPositionAsLower(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.ZDriverPositionAsLower(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def ZDriverInitRange(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.ZDriverInitRange(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverMoveMode(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverMoveMode(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverFocusLimitEnable(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverFocusLimitEnable(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setZDriverInitMode(self, value: str) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setZDriverInitMode(self.Manager, value)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def getZDriverStatus(self) -> (int, int, int, int, int, int):
        isWrong: int = RECODE_FAILURE
        isMoving: int = None
        isLower: int = None
        isUpper: int = None
        isLimit: int = None
        isFocus: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, isMoving, isLower, isUpper, isLimit, isFocus
            items = self.Controller.getZDriverStatus(self.Manager)
            isWrong, isMoving, isLower, isUpper, isLimit, isFocus = items.Item1, items.Item2, items.Item3, items.Item4, items.Item5, items.Item6
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, isMoving, isLower, isUpper, isLimit, isFocus

    def getZDriverManualOptionStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverManualOptionStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverFirmwareStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverFirmwareStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverAbsPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverAbsPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverLowerLimit(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverLowerLimit(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverFocusLimit(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverFocusLimit(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverAcceleration(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverAcceleration(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverSpeed(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverSpeed(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverConvertFactor(self) -> (int, float):
        isWrong: int = RECODE_FAILURE
        Status: float = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverConvertFactor(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverMinAcceleration(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverMinAcceleration(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverMaxAcceleration(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverMaxAcceleration(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverMoveMode(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverMoveMode(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverFocusLimitEnable(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverFocusLimitEnable(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverMinSpeed(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverMinSpeed(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverMaxSpeed(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverMaxSpeed(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverUpperLimit(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverUpperLimit(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getZDriverInitMode(self) -> (int, str):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getZDriverInitMode(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def setObjectiveManualOperation(self, value: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setObjectiveManualOperation(self.Manager, value)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setObjectiveAbsPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setObjectiveAbsPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setObjectiveRelPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setObjectiveRelPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setObjectiveOperationMode(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setObjectiveOperationMode(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setObjectiveDRYMode(self, value: str) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setObjectiveDRYMode(self.Manager, value)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setObjectiveMethodParameter(self, value: int, data: list[str]) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            import System
            array = System.Array[System.String](data)
            isWrong = self.Controller.setObjectiveMethodParameter(self.Manager, int(value), array)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setObjectivePathoMode(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setObjectivePathoMode(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setObjectiveDIP(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setObjectiveDIP(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def getObjectiveStatus(self) -> (int, int, int, int, int):
        isWrong: int = RECODE_FAILURE
        Item1: int = None
        Item2: int = None
        Item3: int = None
        Item4: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Item1, Item2, Item3, Item4
            items = self.Controller.getObjectiveStatus(self.Manager)
            isWrong, Item1, Item2, Item3, Item4 = items.Item1, items.Item2, items.Item3, items.Item4, items.Item5
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Item1, Item2, Item3, Item4

    def getObjectiveManualOperationStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getObjectiveManualOperationStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getObjectiveAbsPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getObjectiveAbsPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getObjectiveOperationStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getObjectiveOperationStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getObjectiveDryMode(self) -> (int, str):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getObjectiveDryMode(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getObjectiveMethodParameter(self, level: int, parameter: int) -> (int, str):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getObjectiveMethodParameter(self.Manager, level, parameter)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getObjectiveMinPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getObjectiveMinPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getObjectiveMaxPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getObjectiveMaxPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getObjectivePathoMode(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getObjectivePathoMode(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def setLampManualOperation(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampManualOperation(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLampAbsPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampAbsPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLampRelPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampRelPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLampTLILMode(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampTLILMode(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLampStepPosition(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampStepPosition(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLampStepMode(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampStepMode(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLampOnOff(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampOnOff(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLampMode(self, enable: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLampMode(self.Manager, int(enable))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def getLampSTATUS(self) -> (int, int, int):
        isWrong: int = RECODE_FAILURE
        IL_Status: int = None
        TL_Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, IL_Status, TL_Status
            items = self.Controller.getLampSTATUS(self.Manager)
            isWrong, IL_Status, TL_Status = items.Item1, items.Item2, items.Item3
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, IL_Status, TL_Status

    def getLampAbsPosition(self) -> (int, int, int):
        isWrong: int = RECODE_FAILURE
        IL_Status: int = None
        TL_Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, IL_Status, TL_Status
            items = self.Controller.getLampAbsPosition(self.Manager)
            isWrong, IL_Status, TL_Status = items.Item1, items.Item2, items.Item3
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, IL_Status, TL_Status

    def getLampMinPosition(self) -> (int, int, int):
        isWrong: int = RECODE_FAILURE
        IL_Status: int = None
        TL_Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, IL_Status, TL_Status
            items = self.Controller.getLampMinPosition(self.Manager)
            isWrong, IL_Status, TL_Status = items.Item1, items.Item2, items.Item3
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, IL_Status, TL_Status

    def getLampMaxPosition(self) -> (int, int, int):
        isWrong: int = RECODE_FAILURE
        IL_Status: int = None
        TL_Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, IL_Status, TL_Status
            items = self.Controller.getLampMaxPosition(self.Manager)
            isWrong, IL_Status, TL_Status = items.Item1, items.Item2, items.Item3
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, IL_Status, TL_Status

    def getLampOnOff(self) -> (int, int, int):
        isWrong: int = RECODE_FAILURE
        IL_Status: int = None
        TL_Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, IL_Status, TL_Status
            items = self.Controller.getLampOnOff(self.Manager)
            isWrong, IL_Status, TL_Status = items.Item1, items.Item2, items.Item3
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, IL_Status, TL_Status

    def getLampStepMode(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getLampStepMode(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getLampManualOperation(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getLampManualOperation(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getLampMode(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: int = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getLampMode(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def setSpotLightManualOperation(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setSpotLightManualOperation(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setSpotLight(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setSpotLight(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setSpotLightMagLevel(self, objective: int, StringNA: str) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setSpotLightMagLevel(self.Manager, objective, StringNA)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setSpotLightMode(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setSpotLightMode(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setSpotLightObjectivePosition(self, objective: int, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setSpotLightObjectivePosition(self.Manager, objective, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def getSpotLightStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getSpotLightStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getSpotLightManualOperation(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getSpotLightManualOperation(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getSpotLight(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getSpotLight(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getSpotLightMagLevel(self) -> (int, str):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getSpotLightMagLevel(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getSpotLightMode(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getSpotLightMode(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getSpotLightObjectivePosition(self, objective: int) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getSpotLightObjectivePosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def setLFBLManualOperation(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLFBLManualOperation(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLFBLInit(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLFBLInit(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLFBLAbsPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLFBLAbsPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setLFBLRelPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setLFBLRelPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def LFBLToMaxPosition(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.LFBLToMaxPosition(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def getLFBLStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getLFBLStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getLFBLManualOperation(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getLFBLManualOperation(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getLFBLAbsPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getLFBLAbsPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getLFBLMaxPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getLFBLMaxPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getLFBLMinPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getLFBLMinPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def setAPBLManualOperation(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setAPBLManualOperation(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setAPBLInit(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setAPBLInit(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setAPBLAbsPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setAPBLAbsPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setAPBLRelPosition(self, value: int) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setAPBLRelPosition(self.Manager, int(value))
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def APBLToMaxPosition(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.APBLToMaxPosition(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def getAPBLStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getAPBLStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getAPBLManualOperation(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getAPBLManualOperation(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getAPBLAbsPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getAPBLAbsPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getAPBLMaxPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getAPBLMaxPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getAPBLMinPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getAPBLMinPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def setDocuPortManualOperation(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setDocuPortManualOperation(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setDocuPortAbsPosition(self, enable: bool) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setDocuPortAbsPosition(self.Manager, True if isinstance(enable, (bool, int)) and enable else False)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def setDocuPortConvertPort(self) -> int:
        isWrong: int = RECODE_FAILURE
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong
            isWrong = self.Controller.setDocuPortConvertPort(self.Manager)
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong

    def getDocuPortStatus(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getDocuPortStatus(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getDocuPortManualOperation(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getDocuPortManualOperation(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getDocuPortAbsPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getDocuPortAbsPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getDocuPortMaxPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getDocuPortMaxPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    def getDocuPortMinPosition(self) -> (int, int):
        isWrong: int = RECODE_FAILURE
        Status: str = None
        try:
            if not self.isAvailable:
                self.ReOpen()
            if not self.isAvailable:
                return isWrong, Status
            items = self.Controller.getDocuPortMinPosition(self.Manager)
            isWrong, Status = items.Item1, items.Item2
        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong, Status

    
    def set_max_lamp(self) -> int:
        return self.setLampAbsPosition(255)

    
    def set_min_lamp(self) -> int:
        return self.setLampAbsPosition(1)

    
    def set_min_lfbl(self) -> int:
        return self.setLFBLAbsPosition(1)

    
    def set_max_lfbl(self):
        isWrong, max_limit = self.getLFBLMaxPosition()
        if isWrong != RECODE_SUCCEED:
            return isWrong
        return self.setLFBLAbsPosition(max_limit)

    
    def set_min_apbl(self) -> int:
        return self.setAPBLAbsPosition(1)

    
    def set_max_apbl(self):
        isWrong, max_limit = self.getAPBLMaxPosition()
        if isWrong != RECODE_SUCCEED:
            return isWrong
        return self.setAPBLAbsPosition(max_limit)

    
    def set_shutter_lamp(self, enable: (bool, int)) -> int:
        return self.setLampOnOff(enable)

    
    def get_shutter_lamp(self) -> (int, int):
        return self.getLampOnOff()

    
    def set_master_event(self):
        return self.setMasterEvents()

    
    def set_objective_event(self):
        return self.setObjectiveEvents()

    
    def set_z_event(self):
        return self.setZDriveEvents()

    
    def set_tl_event(self):
        return self.setAPBLEvents()

    
    def set_field_tl_event(self):
        return self.setLFBLEvents()

    
    def set_led_event(self):
        self.setSpotLightEvents()
        self.setDocuPortEvents()
        return self.setLampEvents()

    
    def set_config_mode(self, enable: (int, bool) = 0):
        """设置配置模式 0: 配置模式关闭 1：配置模式开启"""
        return self.setMasterConfigMode(True if isinstance(enable, (int, bool)) and enable else False)

    
    def get_config_mode(self):
        """设置配置模式 0: 配置模式关闭 1：配置模式开启"""
        return self.getMasterConfigMode()


    def set_position(self, position: (int, float)) -> int:
        return self.setZDriverAbsPosition( position)

    
    def rel_waitmove(self, value: (int, float), mode: int = 1, **args):
        return self.rel_move(value, **args)

    
    def waitForNotMoving(self):
        return self.waitingToStop()





    def set_objective(self, level: int, is_lower_limit: bool = False, **args) -> int:
        return self.changedObjective(level, is_lower_limit, **args)


    
    def set_z_upper_enable(self, enable: (int, bool), **args) -> int:
        return RECODE_SUCCEED

    
    def set_z_lower_enable(self, enable: (int, bool), **args) -> int:
        return RECODE_SUCCEED

    
    def init_objective_range(self, **args) -> int:
        return RECODE_SUCCEED

    
    def init_z_range(self) -> int:
        self.setZDriverLowerLimit(-1)
        return self.setZDriverUpperLimit(-1)

    def wait_init_z_range(self) -> int:
        isWrong: int = RECODE_FAILURE
        for i in range(3):
            isWrong = self.setZDriverLowerLimit(-1)
            if isWrong == RECODE_SUCCEED:
                isWrong = self.setZDriverUpperLimit(-1)
            if isWrong == RECODE_SUCCEED:
                break
        return isWrong

    
    def init_z_speed(self, level: int) -> int:
        return self.set_objective_default_speed(level)


    def get_z_upper_limit(self) -> (int, float):
        return self.getZDriverUpperLimit()

    
    def get_z_lower_limit(self) -> (int, float):
        return self.getZDriverLowerLimit()

    
    def get_z_range(self) -> (int, float, float):
        isWrong, min_limit = self.getZDriverLowerLimit()
        if isWrong != RECODE_SUCCEED:
            return isWrong, None, None
        isWrong, max_limit = self.getZDriverUpperLimit()
        return isWrong, min_limit, max_limit

    
    def get_z_limit(self) -> (int, float, float):
        isWrong, min_limit = self.getZDriverLowerLimit()
        if isWrong != RECODE_SUCCEED:
            return isWrong, None, None
        isWrong, max_limit = self.getZDriverUpperLimit()
        return isWrong, min_limit, max_limit

    

    
    def get_z_speed(self) -> (int, float):
        return self.getZDriverSpeed()

    
    def set_z_acceleration(self, acceleration: (float, int)) -> int:
        return self.setZDriverAcceleration(int(acceleration))

    
    def get_z_acceleration(self) -> (int, float):
        return self.getZDriverAcceleration()

    
    def get_z_enabled(self) -> int:
        return RECODE_SUCCEED

    
    def set_z_enabled(self, enable: (int, bool)) -> int:
        return RECODE_SUCCEED

    
    def setMeasurementOrigin(self, value: (int, float), **args) -> int:
        return RECODE_SUCCEED

    
    def getMeasurementOrigin(self, **args) -> (int, float):
        return RECODE_SUCCEED

    
    def setMeasurementPosition(self, value: (int, float), **args) -> int:
        return RECODE_SUCCEED

    
    def getMeasurementPosition(self, **args) -> (int, float):
        return RECODE_SUCCEED


    def get_z_measurement_origin(self) -> (int, float):
        return RECODE_SUCCEED

    
    def get_z_measurement_position(self) -> (int, float):
        return RECODE_SUCCEED

    
    def set_z_measurement_origin(self, position: (int, float), **args) -> (int, float):
        return RECODE_SUCCEED

    
    def set_z_measurement_position(self, position: (int, float), **args) -> (int, float):
        return RECODE_SUCCEED

    
    def set_z_align_position(self, position: (int, float), **args) -> int:
        return RECODE_SUCCEED


    def get_objective_parameter(self, level: int) -> (int, int):
        return self.getObjectiveMethodParameter( level, 1)

    
    def set_objective_parameter(self, level: int) -> (int, int):
        return RECODE_SUCCEED



    
    def getHandwheelOnOff(self) -> int:
        return self.getManualOptionStatus()

    
    def setHandwheelOnOff(self, enable: (bool, int)) -> int:
        return self.setManualOptionStatus(True if isinstance(enable, (int, bool)) and enable else False)

    
    def set_z_calibrate(self, level: int = None) -> int:
        return RECODE_SUCCEED

    
    def set_z_calibrate_low_limit(self) -> int:
        return RECODE_SUCCEED

    
    def set_z_calibrate_position(self) -> int:
        return RECODE_SUCCEED

    
    def set_align_position(self, target: (int, float)) -> int:
        return RECODE_SUCCEED

    
    def getLAMPOnOFF(self) -> (int, int):
        return self.getLampOnOff()

    
    def getAPBL(self) -> (int, float):
        return self.getAPBLAbsPosition()

    
    def getLFBL(self) -> (int, float):
        return self.getLFBLAbsPosition()

    
    def changedLAMP(self, value: int, **args) -> int:
        return self.setLampAbsPosition(value)

    
    def changedLFBL(self, value: int, **args):
        return self.setLFBLAbsPosition(value)

    
    def changedAPBL(self, value: int, **args) -> int:
        return self.setAPBLAbsPosition(value)

    
    def set_apbl(self, value: (int, float), **args) -> int:
        return self.setAPBLAbsPosition(value)

    
    def set_lfbl(self, value: (int, float), **args) -> int:
        return self.setLFBLAbsPosition(int(value))

    
    def set_lamp(self, value: (int, float), **args) -> int:
        return self.setLampAbsPosition(int(value))

    
    def set_lamp_enable(self, enable: (bool, int), **args) -> int:
        return self.setLampOnOff(True if isinstance(enable, (int, bool)) and enable else False)

    
    def get_lamp_enable(self, **args) -> int:
        return self.getLampOnOff()

    
    def get_apbl(self, **args) -> (int, int):
        return self.getAPBLAbsPosition()

    
    def get_lfbl(self, **args) -> (int, int):
        return self.getLFBLAbsPosition()

    
    def get_lamp(self, **args) -> (int, int):
        return self.getLampAbsPosition()

    
    def set_tl_rl_switch(self, enable: (int, bool), **args):
        return self.setLampOnOff(True if isinstance(enable, (int, bool)) and enable else False)

    
    def init_device_z(self):
        return self.setZDriverInit()

    
    def init_apbl(self):
        return self.setAPBLInit(True)

    
    def init_lfbl(self):
        return self.setLFBLInit(True)

    
    def get_init_status(self) -> int:
        isWrong, status = self.getMasterFirmwareStatus()
        return status if RECODE_SUCCEED == isWrong else None

    
    def get_tl_rl_switch(self) -> (int, int):
        return self.getLampOnOff()

    
    def set_current_position_low_limit(self) -> int:
        return self.ZDriverPositionAsLower()

    
    def get_step_count(self) -> (int, float):
        return self.getZDriverConvertFactor()

    
    def get_min_acceleration(self) -> (int, float):
        return self.getZDriverMinAcceleration()

    
    def get_max_acceleration(self) -> (int, float):
        return self.getZDriverMaxAcceleration()

    MAX_Z_POSITION                          : int = 6804441                         #
    MIN_Z_POSITION                          : int = 0                               #
    MIN_Z_ACC                               : int = 1                               #
    MAX_Z_ACC                               : int = 3612                            #
    MIN_Z_SPEED                             : int = 1                               #
    MAX_Z_SPEED                             : int = 8820000                         #
    LOW_Z_STEP                              : int = 1                               #
    HIG_Z_STEP                              : int = 0                               #