#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：HookRegisterContext.py
@Description：
@Author：XSH
@Time：2025/11/14 16:22
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5                              import Qt
from AppInterfaces.ModelInterface       import ContextModelInterface
from AppContexts.AxisRegisterContext    import AxisRegisterContext
from AppContexts.ModBusRegister         import ModBusRegister
from AppCore.Levels                     import *
from AppUtils.utils                     import *
from AppCore.Requests                   import *

class HookRegisterContext(ContextModelInterface):
    Level                               : int            #          '电机标志　　　　'
    HookClearZero                       : int            #  M3      '挂钩电机清零　　'
    FrontLimit                          : int            #  M14     '挂钩前面限位　　'
    BackLimit                           : int            #  M15     '挂钩后面限位　　'
    PlaceRegister                       : int            #  M16     '托盘到位状态　　'
    DetectorRegister                    : int            #  M17     '检测托盘状态　　'
    LayerRegister                       : int            #  M20     '片仓一层状态　　'
    PickTrayCompleteRegister            : int            #  M44     '取片完成状态　　'
    DropTrayCompleteRegister            : int            #  M45     '放片完成状态　　'
    DetectorTrayCompleteRegister        : int            #  M46     '检测托盘完成状态'
    DetectorChamberCompleteRegister     : int            #  M47     '扫描片仓完成状态'
    ScanCodePickTrayCompleteRegister    : int            #  M48     '扫码取片到位状态'
    EmptyTrayReturnStatusRegister       : int            #  M50     '空挂退出完成状态'
    ForceQuitRegister                   : int            #  M59     '设置强制退出功能'
    PickTrayRegister                    : int            #  M60     '片仓取出托盘功能'
    DropTrayRegister                    : int            #  M61     '托盘放回片仓功能'
    DetectorTrayRegister                : int            #  M62     '检测指定托盘功能'
    DetectorChamberRegister             : int            #  M63     '检测片仓托盘功能'
    ScanCodePickRegister                : int            #  M64     '扫码托片功能　　'
    EmptyTrayReturnRegister             : int            #  M65     '空挂返回功能　　'
    ForwardRegister                     : int            #  M72     '挂钩电机前进功能'
    BackwardRegister                    : int            #  M73     '挂钩电机后退功能'
    ScanCodePlaceRegister               : int            #  M80     '到位扫码功能　　'
    ScanCodeCompleteMoveRegister        : int            #  M81     '扫码完成前进功能'
    AxisXMalfunction                    : int            #
    AxisYMalfunction                    : int            #
    AxisZMalfunction                    : int            #
    ForwardMalfunction                  : int            #  M406    '挂钩前进故障状态'
    BackwardMalfunction                 : int            #  M407    '挂钩后退故障状态'
    HookResetRegister                   : int            #  M423    '挂钩电机复位功能'
    Position                            : int            #  D100    '当前挂钩位置　　'
    Velocity                            : int            #  D102    '当前挂钩速度　　'
    SetLayerHoverHeightRegister         : int            #  D1200   '设置悬停高度功能'
    SetLayerDragHoverHeightRegister     : int            #  D1202   '设置拖拽高度功能'
    SetLayerSpacingHeightRegister       : int            #  D1204   '设置片仓间距功能'
    SetAxisXPickPositionRegister        : int            #  D1206   '设置Ｘ轴取片位置'
    SetAxisYPickPositionRegister        : int            #  D1208   '设置Ｙ轴取片位置'
    SetScanCodePositionRegister         : int            #  D1210   '设置扫码位置功能'
    SetScanCodeSpacingRegister          : int            #  D1212   '设置扫码间距功能'
    SetAxisXDetectorPositionRegister    : int            #  D1214   '设置Ｘ轴检测位置'
    SetAxisYDetectorPositionRegister    : int            #  D1216   '设置Ｙ轴检测位置'
    SetLayerCountRegister               : int            #  D1218   '设置片仓层数功能'
    SetDetectorLayerPositionRegister    : int            #  D1220   '检测片仓Ｚ轴位置'
    ChamberStatusRegister               : int            #  M51     '检测片仓返回状态'
    CheckChamberRegister                : int            #  M67     '检测片仓是否存在'
    SetAxisXCheckPositionRegister       : int            #  D1222   '设置Ｘ轴取片位置'
    SetAxisYCheckPositionRegister       : int            #  D1224   '设置Ｙ轴取片位置'
    SetAxisZCheckHoverHeightRegister    : int            #  D1226   '设置检测悬停高度'

    def __init__(self, Information: str = "", **args):
        super(HookRegisterContext, self).__init__()
        self.initialization(Information)
        self.initParameter(**args)


    @classmethod
    def instance(cls, **args) -> 'HookRegisterContext':
        result: cls = cls.__new__(cls)
        result.__init__(Information="", **args)
        return result


    def initValue(self):
        super(HookRegisterContext, self).initValue()
        self.Level                               = AxisLevel.AxisH          #
        self.HookClearZero                       = 3                        #
        self.FrontLimit                          = 14                       #
        self.BackLimit                           = 15                       #
        self.PlaceRegister                       = 16                       #
        self.DetectorRegister                    = 17                       #
        self.LayerRegister                       = 20                       #
        self.PickTrayCompleteRegister            = 44                       #
        self.DropTrayCompleteRegister            = 45                       #
        self.DetectorTrayCompleteRegister        = 46                       #
        self.DetectorChamberCompleteRegister     = 47                       #
        self.ScanCodePickTrayCompleteRegister    = 48                       #
        self.EmptyTrayReturnStatusRegister       = 50                       #
        self.ForceQuitRegister                   = 59                       #
        self.PickTrayRegister                    = 60                       #
        self.DropTrayRegister                    = 61                       #
        self.DetectorTrayRegister                = 62                       #
        self.DetectorChamberRegister             = 63                       #
        self.ScanCodePickRegister                = 64                       #
        self.EmptyTrayReturnRegister             = 65                       #
        self.ForwardRegister                     = 72                       #
        self.BackwardRegister                    = 73                       #
        self.ScanCodePlaceRegister               = 80                       #
        self.ScanCodeCompleteMoveRegister        = 81                       #
        self.AxisXMalfunction                    = 401                      #
        self.AxisYMalfunction                    = 403                      #
        self.AxisZMalfunction                    = 405                      #
        self.ForwardMalfunction                  = 406                      #
        self.BackwardMalfunction                 = 407                      #
        self.HookResetRegister                   = 423                      #
        self.Position                            = 100                      #
        self.Velocity                            = 102                      #
        self.SetLayerHoverHeightRegister         = 1200                     #
        self.SetLayerDragHoverHeightRegister     = 1202                     #
        self.SetLayerSpacingHeightRegister       = 1204                     #
        self.SetAxisXPickPositionRegister        = 1206                     #
        self.SetAxisYPickPositionRegister        = 1208                     #
        self.SetScanCodePositionRegister         = 1210                     #
        self.SetScanCodeSpacingRegister          = 1212                     #
        self.SetAxisXDetectorPositionRegister    = 1214                     #
        self.SetAxisYDetectorPositionRegister    = 1216                     #
        self.SetLayerCountRegister               = 1218                     #
        self.SetDetectorLayerPositionRegister    = 1220                     #
        self.ChamberStatusRegister               = 51                       #
        self.CheckChamberRegister                = 67                       #
        self.SetAxisXCheckPositionRegister       = 1222                     #
        self.SetAxisYCheckPositionRegister       = 1224                     #
        self.SetAxisZCheckHoverHeightRegister    = 1226                     #
        self.flushInfo()

    def initAxisH(self):
        self.Level                               = AxisLevel.AxisH          #
        self.HookClearZero                       = 3                        #
        self.FrontLimit                          = 14                       #
        self.BackLimit                           = 15                       #
        self.PlaceRegister                       = 16                       #
        self.DetectorRegister                    = 17                       #
        self.LayerRegister                       = 20                       #
        self.PickTrayCompleteRegister            = 44                       #
        self.DropTrayCompleteRegister            = 45                       #
        self.DetectorTrayCompleteRegister        = 46                       #
        self.DetectorChamberCompleteRegister     = 47                       #
        self.ScanCodePickTrayCompleteRegister    = 48                       #
        self.EmptyTrayReturnStatusRegister       = 50                       #
        self.ForceQuitRegister                   = 59                       #
        self.PickTrayRegister                    = 60                       #
        self.DropTrayRegister                    = 61                       #
        self.DetectorTrayRegister                = 62                       #
        self.DetectorChamberRegister             = 63                       #
        self.ScanCodePickRegister                = 64                       #
        self.EmptyTrayReturnRegister             = 65                       #
        self.ForwardRegister                     = 72                       #
        self.BackwardRegister                    = 73                       #
        self.ScanCodePlaceRegister               = 80                       #
        self.ScanCodeCompleteMoveRegister        = 81                       #
        self.AxisXMalfunction                    = 401                      #
        self.AxisYMalfunction                    = 403                      #
        self.AxisZMalfunction                    = 405                      #
        self.ForwardMalfunction                  = 406                      #
        self.BackwardMalfunction                 = 407                      #
        self.HookResetRegister                   = 423                      #
        self.Position                            = 100                      #
        self.Velocity                            = 102                      #
        self.SetLayerHoverHeightRegister         = 1200                     #
        self.SetLayerDragHoverHeightRegister     = 1202                     #
        self.SetLayerSpacingHeightRegister       = 1204                     #
        self.SetAxisXPickPositionRegister        = 1206                     #
        self.SetAxisYPickPositionRegister        = 1208                     #
        self.SetScanCodePositionRegister         = 1210                     #
        self.SetScanCodeSpacingRegister          = 1212                     #
        self.SetAxisXDetectorPositionRegister    = 1214                     #
        self.SetAxisYDetectorPositionRegister    = 1216                     #
        self.SetLayerCountRegister               = 1218                     #
        self.SetDetectorLayerPositionRegister    = 1220                     #
        self.ChamberStatusRegister               = 51                       #
        self.CheckChamberRegister                = 67                       #
        self.SetAxisXCheckPositionRegister       = 1222                     #
        self.SetAxisYCheckPositionRegister       = 1224                     #
        self.SetAxisZCheckHoverHeightRegister    = 1226                     #
        self.flushInfo()


    def flushInfo(self):
        if self.Level == AxisLevel.AxisX:
            self.Information = "Ｘ轴地址"
        elif self.Level == AxisLevel.AxisY:
            self.Information = "Ｙ轴地址"
        elif self.Level == AxisLevel.AxisH:
            self.Information = "快扫Ｈ轴地址"
        elif self.Level == AxisLevel.AxisZ:
            self.Information = "快扫Ｚ轴地址"
        elif self.Level == AxisLevel.ScanX:
            self.Information = "快扫Ｘ轴地址"
        elif self.Level == AxisLevel.ScanY:
            self.Information = "快扫Ｙ轴地址"
        elif self.Level == AxisLevel.SlowScanX:
            self.Information = "慢扫Ｘ轴地址"
        elif self.Level == AxisLevel.SlowScanY:
            self.Information = "慢扫Ｙ轴地址"
        elif self.Level == AxisLevel.DropOilX:
            self.Information = "滴油Ｘ轴地址"
        elif self.Level == AxisLevel.DropOilY:
            self.Information = "滴油Ｙ轴地址"
        elif self.Level == AxisLevel.AxisZ:
            self.Information = "片仓Ｚ轴地址"
        elif self.Level == AxisLevel.Detection:
            self.Information = "传感器地址"
        else:
            self.Information = "Ｘ轴地址"
    __slots__ = (
        'Level'                                  ,
        'HookClearZero'                          ,
        'FrontLimit'                             ,
        'BackLimit'                              ,
        'PlaceRegister'                          ,
        'DetectorRegister'                       ,
        'LayerRegister'                          ,
        'PickTrayCompleteRegister'               ,
        'DropTrayCompleteRegister'               ,
        'DetectorTrayCompleteRegister'           ,
        'DetectorChamberCompleteRegister'        ,
        'ScanCodePickTrayCompleteRegister'       ,
        'EmptyTrayReturnStatusRegister'          ,
        'ForceQuitRegister'                      ,
        'PickTrayRegister'                       ,
        'DropTrayRegister'                       ,
        'DetectorTrayRegister'                   ,
        'DetectorChamberRegister'                ,
        'ScanCodePickRegister'                   ,
        'EmptyTrayReturnRegister'                ,
        'ForwardRegister'                        ,
        'BackwardRegister'                       ,
        'ScanCodePlaceRegister'                  ,
        'ScanCodeCompleteMoveRegister'           ,
        'AxisXMalfunction'                       ,
        'AxisYMalfunction'                       ,
        'AxisZMalfunction'                       ,
        'ForwardMalfunction'                     ,
        'BackwardMalfunction'                    ,
        'HookResetRegister'                      ,
        'Position'                               ,
        'Velocity'                               ,
        'SetLayerHoverHeightRegister'            ,
        'SetLayerDragHoverHeightRegister'        ,
        'SetLayerSpacingHeightRegister'          ,
        'SetAxisXPickPositionRegister'           ,
        'SetAxisYPickPositionRegister'           ,
        'SetScanCodePositionRegister'            ,
        'SetScanCodeSpacingRegister'             ,
        'SetAxisXDetectorPositionRegister'       ,
        'SetAxisYDetectorPositionRegister'       ,
        'SetLayerCountRegister'                  ,
        'SetDetectorLayerPositionRegister'       ,
        'ChamberStatusRegister'                   ,
        'CheckChamberRegister'                   ,
        'SetAxisXCheckPositionRegister'          ,
        'SetAxisYCheckPositionRegister'          ,
        'SetAxisZCheckHoverHeightRegister'       ,
    )



    __types__ = (
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
        int     ,
    )