| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 | using Aitex.Core.RT.DataCenter;using Aitex.Core.RT.Device;using Aitex.Core.RT.Log;using Aitex.Core.RT.OperationCenter;using Aitex.Core.Util;using MECF.Framework.Common.Beckhoff.ModuleIO;using MECF.Framework.Common.CommonData.Prewet;using MECF.Framework.Common.Device.Safety;using MECF.Framework.Common.Equipment;using MECF.Framework.Common.TwinCat;using MECF.Framework.Common.Utilities;using CyberX8_Core;using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;using CyberX8_RT.Devices.AXIS;using Aitex.Core.RT.SCCore;using MECF.Framework.Common.WaferHolder;using MECF.Framework.Common.IOCore;namespace CyberX8_RT.Devices.Safety{    public class SafetyDevice : BaseDevice, IDevice    {        #region 常量        private const string TWINCAT_STATE = "TwincatState";        private const string MAIN_COMM_ERR = "MainCommErr";        private const string LOADER_PUF_COMM_ERR="LoaderPufCommErr";        private const string SRD_COMM_ERR = "SrdCommErr";        private const string TRANSPORTER_COMM_ERR="TransportCommErr";        private const string MAIN_FUNCTION_BLOCK_ERR= "MainFunctionBlockErr";        private const string LOADER_PUF_FUNCTION_BLOCK_ERR="LoaderPufFunctionBlockErr";        private const string SRD_FUNCTION_BLOCK_ERR = "SrdFunctionBlockErr";        private const string TRANSPORTER_FUNCTION_BLOCK_ERR="TransporterFunctionBlockErr";        private const string IS_INITIALIZED = "IsInitialized";        private const double OP_HOT_CONNECT_STATE = 8;        #region Hot Connect        private const string HOT_CONNECT_STATE = "HotConnectState";        private const string LOADER_HOT_CONNECT_STATE= "LoaderHotConnectState";        private const string PUF_HOT_CONNECT_STATE="PufHotConnectState";        private const string SRD_HOT_CONNECT_STATE="SrdHotConnectState";        private const string TRANSPORTER_HOT_CONNECT_STATE="TransporterHotConnectState";        private const string LDR_HOT_CONNECT_STATE="LdrHotConnectState";        private const string PRC_HOT_CONNECT_STATE="PrcHotConnectState";        private const string RESERVOIR1_HOT_CONNECT_STATE="Reservoir1HotConnectState";        private const string RESERVOIR2_HOT_CONNECT_STATE="Reservoir2HotConnectState";        private const string FFU_HOT_CONNECT_STATE="FFUHotConnectState";        #endregion        #region Restart        private const string RUNSTOP = "RunStop";        private const string ERRACK = "ErrAck";        private const string SLS_RESTART = "SlsRestart";        private const string TX_STO_MON_Restart = "TxStoMonRestart";        private const string TX_STO1_ESTOP_Restart = "TxSto1EstopRestart";        private const string TX_STO2_ESTOP_RESTART = "TxSto2EstopRestart";        private const string LDR_PUF_STO_MON_RESTART = "LdrPufStoMonRestart";        private const string LDR_PUF_STO1_ESTOP_RESTART = "LdrPufSto1EstopRestart";        private const string LDR_PUF_STO2_ESTOP_RESTART = "LdrPufSto2EstopRestart";        private const string SRD_STO_ESTOP_RESTART = "SrdStoEstopRestart";        private const string PUMP_STO_ESTOP_RESTART = "PumpStoEstopRestart";        private const string FLUID_ESTOP_RESTART = "FluidEstopRestart";        #endregion        #region Door Lock        private const string LOADER_DOOR_LOCK= "LoaderDoorLock";        private const string LOADER_DOOR_LOCKED="LoaderDoorLocked";        private const string LOADER_PANEL_REMOVED="LoaderPanelRemoved";        private const string LOWER_LOADER_PANEL_REMOVED = "LowerLoaderPanelRemoved";        private const string BUFFER_DOOR_LOCK="BufferDoorLock";        private const string BUFFER_DOOR_LOCKED="BufferDoorLocked";        private const string BUFFER_PANEL_REMOVED = "BufferPanelRemoved";        private const string PROCESS_DOOR_LOCK="ProcessDoorLock";        private const string PROCESS_DOOR1_LOCKED="ProcessDoor1Locked";        private const string PROCESS_DOOR2_LOCKED="ProcessDoor2Locked";        private const string PROCESS_DOOR3_LOCKED="ProcessDoor3Locked";        private const string PROCESS_DOOR4_LOCKED="ProcessDoor4Locked";        private const string PROCESS_UPPER_PANELS_ON = "ProcessUpperPanelsOn";        #endregion        private const string SRD_TOP_PANEL_REMOVED="SrdTopPanelRemoved";        private const string SRD_LOWER_PANEL_REMOVED="SrdLowerPanelRemoved";        private const string PLUMBING_DOOR_CLOSED = "PlumbingDoorClosed";        private const string PROCESS_HALT_BUTTON1="ProcessHaltButton1";        private const string PROCESS_HALT_BUTTON2="ProcessHaltButton2";        private const string LOADER_HALT_BUTTON= "LoaderHaltButton";        private const string MODE_SELECTOR_SWITCH="ModeSelectorSwitch";        private const string MODE_SIREN="ModeSiren";        #region SLS        private const string LOADER_ROTATION_SLS="LoaderRotationSls";        private const string LOADER_SWINGA_SLS="LoaderSwingASls";        private const string LOADER_SWINGB_SLS="LoaderSwingBSls";        private const string LOADER_TILTA_SLS="LoaderTiltASls";        private const string LOADER_TILTB_SLS="LoaderTiltBSls";        private const string PUF1_VERTICAL_SLS="Puf1VerticalSls";        private const string PUF2_VERTICAL_SLS="Puf2VerticalSls";        private const string LOADER_GANTRY_SLS="LoaderGantrySls";        private const string LOADER_ELEVATOR_SLS="LoaderElevatorSls";        private const string PROCESS_GANTRY_SLS="ProcessGantrySls";        private const string PROCESS_ELEVATOR_SLS="ProcessElevatorSls";        #endregion        #region Disable        private const string PUF_VERTICAL_DISABLE= "PufVerticalDisable";        private const string PUF1_FLIP_ROTATION_DISABLE="Puf1FlipRotationDisable";        private const string PUF2_FLIP_ROTATION_DISABLE="Puf2FlipRotationDisable";        private const string LOADER_DISABLE="LoaderDisable";        private const string TRANSPORTER_DISABLE="TransporterDisable";        private const string SRD_ARM_DISABLE="SrdArmDisable";        private const string SRD_ROTATION_DISABLE="SrdRotationDisable";        #endregion        #region safety        private const string TRANSPORTER_SAFE_SLS="TransporterSafeSls";        private const string LOADER_SAFE_SLS="LoaderSafeSls";        private const string PUF_VERTICAL_SAFE_SLS="PufVerticalSafeSls";        private const string LOADER_SAFE_STO="LoaderSafeSto";        private const string PUF_VERTICAL_SAFE_STO="PufVerticalSafeSto";        private const string PUF1_FLIP_ROTATION_SAFE_STO="Puf1FlipRotationSafeSto";        private const string PUF2_FLIP_ROTATION_SAFE_STO="Puf2FlipRotationSafeSto";        private const string TRANSPORTER_SAFE_STO="TransporterSafeSto";        private const string SRD_ROTATION_SAFE_STO = "SrdRotationSafeSto";        private const string SRD_ARM_SAFE_STO="SrdArmSafeSto";        #endregion        #region Plumbling        private const string PUMP_EDM="PumpEdm";        private const string RESERVIOR_HIGH_LEVEL="ReservoirHighLevel";        private const string FLUID_ENABLE_EDM="FluidEnableEdm";        #endregion        private const string SRD_ARM_RESET="SRDArmReset";        private const string SAFETY_DATA="SafetyData";        #endregion        #region 内部变量        /// <summary>        /// Reset Routine        /// </summary>        private SafetyResetRoutine _resetRoutine;        /// <summary>        /// All Switch On Routine        /// </summary>        private SafetyNewAllOnRoutine _allOnRoutine;        /// <summary>        /// AllOnRoutine状态        /// </summary>        private RState _allOnStatus;        /// <summary>        /// 操作当前状态        /// </summary>        private RState _status;        /// <summary>        /// 变量是否初始化字典        /// </summary>        private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();        /// <summary>        /// 定时器Job        /// </summary>        PeriodicJob _periodicJob = null;        #endregion        #region 属性        /// <summary>        /// 数据对象        /// </summary>        public SafetyData SafetyData { get; set; }        /// <summary>        /// 状态        /// </summary>        public RState Status { get; set; }        /// <summary>        /// 所有io变量是否初始化        /// </summary>        public bool IOInitialized { get { return IOVariableDictionaryUtil.AllIoVariableInitialized(eEvent.ERR_SAFETY,Module,_variableInitializeDic); } }        #endregion        /// <summary>        /// 构造函数        /// </summary>        /// <param name="moduleName"></param>        public SafetyDevice() : base("Safety", "Safety", "Safety", "Safety")        {                       SafetyData = new SafetyData();        }        /// <summary>        /// 定时器        /// </summary>        /// <returns></returns>        private bool OnTimer()        {            if (_status==RState.Running)            {                _status = _resetRoutine.Monitor();                if(_status==RState.End)                {                    LOG.WriteLog(eEvent.INFO_SAFETY, Module, "Reset Complete");                }                else if(_status==RState.Failed)                {                    LOG.WriteLog(eEvent.ERR_SAFETY, Module, "Reset Error");                }            }            //AllOnRoutine监控            if (_allOnStatus == RState.Running)            {                _allOnStatus = _allOnRoutine.Monitor();                if (_allOnStatus == RState.End)                {                    LOG.WriteLog(eEvent.INFO_SAFETY, Module, "All On Complete");                }                else if (_allOnStatus == RState.Failed)                {                    LOG.WriteLog(eEvent.ERR_SAFETY, Module, "All On Error");                }            }            SLSAxisModeSiren();            //WaferShuttleUsageMonitor            WaferHolderManager.Instance.WaferShuttleUsageMonitor();            return true;        }        /// <summary>        /// SLS模块下Axis Mode Siren        /// </summary>        private void SLSAxisModeSiren()        {            int count = 0;            //count += AxisModeSirenOn(SafetyData.Puf1VerticalSls, $"{ModuleName.PUF1}.Vertical");            //count += AxisModeSirenOn(SafetyData.Puf2VerticalSls, $"{ModuleName.PUF2}.Vertical");            //count += AxisModeSirenOn(SafetyData.LoaderTiltASls, $"{ModuleName.Loader1}.TiltA");            //count += AxisModeSirenOn(SafetyData.LoaderTiltBSls, $"{ModuleName.Loader1}.TiltB");            //count += AxisModeSirenOn(SafetyData.LoaderSwingASls, $"{ModuleName.Loader1}.SwingA");            //count += AxisModeSirenOn(SafetyData.LoaderSwingBSls, $"{ModuleName.Loader1}.SwingB");            //count += AxisModeSirenOn(SafetyData.LoaderRotationSls, $"{ModuleName.Loader1}.Rotation");            //count += AxisModeSirenOn(SafetyData.LoaderGantrySls, $"{ModuleName.Transporter2}.Gantry");            //count += AxisModeSirenOn(SafetyData.LoaderElevatorSls, $"{ModuleName.Transporter2}.Elevator");            //count += AxisModeSirenOn(SafetyData.ProcessGantrySls, $"{ModuleName.Transporter1}.Gantry");            //count += AxisModeSirenOn(SafetyData.ProcessElevatorSls, $"{ModuleName.Transporter1}.Elevator");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.PUF1}.Vertical");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.PUF2}.Vertical");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Loader1}.TiltA");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Loader1}.TiltB");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Loader1}.ShuttleA");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Loader1}.ShuttleB");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Loader1}.Rotation");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Transporter2}.Gantry");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Transporter2}.Elevator");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Transporter1}.Gantry");            count += AxisModeSirenOn(!SafetyData.ModeSelectorSwitch, $"{ModuleName.Transporter1}.Elevator");            if (count==0&&SafetyData.ModeSiren)            {                ModeSirenOff();            }        }        /// <summary>        /// Axis运动Mode Siren On        /// </summary>        /// <param name="jetAxisBase"></param>        private int AxisModeSirenOn(bool sls,string axisName)        {            JetAxisBase axis = DEVICE.GetDevice<JetAxisBase>(axisName);            if (axis != null && axis.IsSwitchOn)            {                if (axis.IsRun&&sls)                {                    ModeSirenOn();                    return 1;                }            }            return 0;        }        /// <summary>        /// 初始化        /// </summary>        /// <returns></returns>        public bool Initialize()        {            InitializeRoutine();            InitializeData();            SubscribeValueAction();            InitializeOperation();            _periodicJob = new PeriodicJob(200, OnTimer, $"{Module}.OnTimer", true);            return true;        }        /// <summary>        /// 初始化Routine        /// </summary>        private void InitializeRoutine()        {            _resetRoutine = new SafetyResetRoutine(Module);            _allOnRoutine = new SafetyNewAllOnRoutine(Module);        }        /// <summary>        /// 初始化DATA        /// </summary>        private void InitializeData()        {            DATA.Subscribe($"{Module}.{SAFETY_DATA}",() => SafetyData, SubscriptionAttribute.FLAG.IgnoreSaveDB);            DATA.Subscribe($"{Module}.{IS_INITIALIZED}", () => IOInitialized, SubscriptionAttribute.FLAG.IgnoreSaveDB);            DATA.Subscribe($"{Module}.TwincatState", () => SafetyData.TwincatState, SubscriptionAttribute.FLAG.IgnoreSaveDB);        }        /// <summary>        /// 初始化Operation        /// </summary>        private void InitializeOperation()        {            OP.Subscribe($"{Module}.LockProcessDoors", (cmd,args) => LockProcessDoor());            OP.Subscribe($"{Module}.UnlockProcessDoors", (cmd, args) => UnlockProcessDoor());            OP.Subscribe($"{Module}.LockLoaderDoors", (cmd, args) => LockLoaderDoor());            OP.Subscribe($"{Module}.UnlockLoaderDoors", (cmd, args) => UnlockLoaderDoor());            OP.Subscribe($"{Module}.LockBufferDoors", (cmd, args) => LockBufferDoor());            OP.Subscribe($"{Module}.UnlockBufferDoors", (cmd, args) => UnlockBufferDoor());            OP.Subscribe($"{Module}.ResetOperation",(cmd, args) => ResetOperation());            OP.Subscribe($"{Module}.AllOnOperation", (cmd, args) => AllOnOperation());        }        /// <summary>        /// 订阅变量数值发生变化        /// </summary>        private void SubscribeValueAction()        {            BeckhoffIoSubscribeUpdateVariable( MAIN_COMM_ERR);            BeckhoffIoSubscribeUpdateVariable( LOADER_PUF_COMM_ERR);            BeckhoffIoSubscribeUpdateVariable( SRD_COMM_ERR);            BeckhoffIoSubscribeUpdateVariable( TRANSPORTER_COMM_ERR);            BeckhoffIoSubscribeUpdateVariable( MAIN_FUNCTION_BLOCK_ERR);            BeckhoffIoSubscribeUpdateVariable( LOADER_PUF_FUNCTION_BLOCK_ERR);            BeckhoffIoSubscribeUpdateVariable( SRD_FUNCTION_BLOCK_ERR);            BeckhoffIoSubscribeUpdateVariable( TRANSPORTER_FUNCTION_BLOCK_ERR);            BeckhoffIoSubscribeUpdateVariable( TWINCAT_STATE);            BeckhoffIoSubscribeUpdateVariable( LOADER_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( FFU_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( PRC_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( LDR_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( TRANSPORTER_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( SRD_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( PUF_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( RESERVOIR2_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( RESERVOIR1_HOT_CONNECT_STATE);            BeckhoffIoSubscribeUpdateVariable( RUNSTOP);            BeckhoffIoSubscribeUpdateVariable( ERRACK);            BeckhoffIoSubscribeUpdateVariable( SLS_RESTART);            BeckhoffIoSubscribeUpdateVariable( TX_STO1_ESTOP_Restart);            BeckhoffIoSubscribeUpdateVariable( TX_STO_MON_Restart);            BeckhoffIoSubscribeUpdateVariable( TX_STO2_ESTOP_RESTART);            BeckhoffIoSubscribeUpdateVariable( LDR_PUF_STO_MON_RESTART);            BeckhoffIoSubscribeUpdateVariable( LDR_PUF_STO1_ESTOP_RESTART);            BeckhoffIoSubscribeUpdateVariable( LDR_PUF_STO2_ESTOP_RESTART);            BeckhoffIoSubscribeUpdateVariable( SRD_STO_ESTOP_RESTART);            BeckhoffIoSubscribeUpdateVariable( PUMP_STO_ESTOP_RESTART);            BeckhoffIoSubscribeUpdateVariable( FLUID_ESTOP_RESTART);            BeckhoffIoSubscribeUpdateVariable( LOADER_DOOR_LOCK);            BeckhoffIoSubscribeUpdateVariable( LOADER_DOOR_LOCKED);            BeckhoffIoSubscribeUpdateVariable( LOADER_PANEL_REMOVED);            BeckhoffIoSubscribeUpdateVariable( LOWER_LOADER_PANEL_REMOVED);            BeckhoffIoSubscribeUpdateVariable( BUFFER_DOOR_LOCK);            BeckhoffIoSubscribeUpdateVariable( BUFFER_DOOR_LOCKED);            BeckhoffIoSubscribeUpdateVariable( BUFFER_PANEL_REMOVED);            BeckhoffIoSubscribeUpdateVariable( PROCESS_DOOR_LOCK);            BeckhoffIoSubscribeUpdateVariable( PROCESS_DOOR1_LOCKED);            BeckhoffIoSubscribeUpdateVariable( PROCESS_DOOR2_LOCKED);            BeckhoffIoSubscribeUpdateVariable( PROCESS_DOOR3_LOCKED);            BeckhoffIoSubscribeUpdateVariable( PROCESS_DOOR4_LOCKED);            BeckhoffIoSubscribeUpdateVariable( PROCESS_UPPER_PANELS_ON);            BeckhoffIoSubscribeUpdateVariable( SRD_TOP_PANEL_REMOVED);            BeckhoffIoSubscribeUpdateVariable( SRD_LOWER_PANEL_REMOVED);            BeckhoffIoSubscribeUpdateVariable( PLUMBING_DOOR_CLOSED);            BeckhoffIoSubscribeUpdateVariable( PROCESS_HALT_BUTTON1);            BeckhoffIoSubscribeUpdateVariable( PROCESS_HALT_BUTTON2);            BeckhoffIoSubscribeUpdateVariable( LOADER_HALT_BUTTON);            BeckhoffIoSubscribeUpdateVariable( MODE_SELECTOR_SWITCH);            BeckhoffIoSubscribeUpdateVariable( MODE_SIREN);            BeckhoffIoSubscribeUpdateVariable( LOADER_ROTATION_SLS);            BeckhoffIoSubscribeUpdateVariable( LOADER_SWINGA_SLS);            BeckhoffIoSubscribeUpdateVariable( LOADER_SWINGB_SLS);            BeckhoffIoSubscribeUpdateVariable( LOADER_TILTA_SLS);            BeckhoffIoSubscribeUpdateVariable( LOADER_TILTB_SLS);            BeckhoffIoSubscribeUpdateVariable( PUF1_VERTICAL_SLS);            BeckhoffIoSubscribeUpdateVariable( PUF2_VERTICAL_SLS);            BeckhoffIoSubscribeUpdateVariable( LOADER_GANTRY_SLS);            BeckhoffIoSubscribeUpdateVariable( LOADER_ELEVATOR_SLS);            BeckhoffIoSubscribeUpdateVariable( PROCESS_GANTRY_SLS);            BeckhoffIoSubscribeUpdateVariable( PROCESS_ELEVATOR_SLS);            BeckhoffIoSubscribeUpdateVariable( PUF_VERTICAL_DISABLE);            BeckhoffIoSubscribeUpdateVariable( PUF1_FLIP_ROTATION_DISABLE);            BeckhoffIoSubscribeUpdateVariable( PUF2_FLIP_ROTATION_DISABLE);            BeckhoffIoSubscribeUpdateVariable( LOADER_DISABLE);            BeckhoffIoSubscribeUpdateVariable( TRANSPORTER_DISABLE);            BeckhoffIoSubscribeUpdateVariable( SRD_ARM_DISABLE);            BeckhoffIoSubscribeUpdateVariable( SRD_ROTATION_DISABLE);            BeckhoffIoSubscribeUpdateVariable( TRANSPORTER_SAFE_SLS);            BeckhoffIoSubscribeUpdateVariable( LOADER_SAFE_SLS);            BeckhoffIoSubscribeUpdateVariable( PUF_VERTICAL_SAFE_SLS);            BeckhoffIoSubscribeUpdateVariable( LOADER_SAFE_STO);            BeckhoffIoSubscribeUpdateVariable( PUF_VERTICAL_SAFE_STO);            BeckhoffIoSubscribeUpdateVariable( PUF1_FLIP_ROTATION_SAFE_STO);            BeckhoffIoSubscribeUpdateVariable( PUF2_FLIP_ROTATION_SAFE_STO);            BeckhoffIoSubscribeUpdateVariable( TRANSPORTER_SAFE_STO);            BeckhoffIoSubscribeUpdateVariable( SRD_ARM_SAFE_STO);            BeckhoffIoSubscribeUpdateVariable( SRD_ROTATION_SAFE_STO);            BeckhoffIoSubscribeUpdateVariable( PUMP_EDM);            BeckhoffIoSubscribeUpdateVariable( RESERVIOR_HIGH_LEVEL);            BeckhoffIoSubscribeUpdateVariable(FLUID_ENABLE_EDM);            BeckhoffIoSubscribeUpdateVariable(SRD_ARM_RESET);        }        /// <summary>        /// 订阅IO变量        /// </summary>        /// <param name="variable"></param>        private void BeckhoffIoSubscribeUpdateVariable(string variable)        {            _variableInitializeDic[variable] = false;            IOModuleManager.Instance.SubscribeModuleVariable(Module,variable, UpdateVariableValue);        }        /// <summary>        /// 更新变量数值        /// </summary>        /// <param name="variable"></param>        /// <param name="value"></param>        private void UpdateVariableValue(string variable, object value)        {            if (!SafetyData.IsDataInitialized)            {                SafetyData.IsDataInitialized = true;            }            PropertyInfo property = SafetyData.GetType().GetProperty(variable);            if (property != null)            {                property.SetValue(SafetyData, value);            }            if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])            {                _variableInitializeDic[variable] = true;            }            if(variable.EndsWith("Sls"))            {                SlsChangedSpeed(variable,(bool)value);            }            CheckIsDataAbonrmal(variable, value);        }        #region 监控指示灯是否异常 方法        /// <summary>        /// 监控指示灯是否异常,是则打印log        /// </summary>        /// <param name="variable"></param>        /// <param name="value"></param>        private void CheckIsDataAbonrmal(string variable,object value)        {            if (variable == "ReservoirHighLevel" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "ReservoirHigh Level Error");            }            else if (variable == "MainCommErr" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "MainCommErr Error");            }            else if (variable == "LoaderPufCommErr" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "LoaderPufCommErr Error");            }            else if (variable == "SrdCommErr" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "SrdCommErr Error");            }            else if (variable == "TransportCommErr" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "TransportCommErr Error");            }            else if (variable == "MainFunctionBlockErr" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "MainFunctionBlockErr Error");            }            else if (variable == "LoaderPufFunctionBlockErr" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "LoaderPufFunctionBlockErr Error");            }            else if (variable == "SrdFunctionBlockErr" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "SrdFunctionBlockErr Error");            }            else if (variable == "TransporterFunctionBlockErr" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "TransporterFunctionBlockErr Error");            }            else if (variable == "ProcessHaltButton1" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "ProcessHaltButton1 Activate");            }            else if (variable == "ProcessHaltButton2" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "ProcessHaltButton2 Activate");            }            else if (variable == "LoaderHaltButton" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "LoaderHaltButton Activate");            }            else if (variable == "LoaderPanelRemoved" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "LoaderPanelRemoved Activate");            }            else if (variable == "BufferPanelRemoved" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "BufferPanelRemoved Activate");            }            else if (variable == "SrdTopPanelRemoved" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "SrdTopPanelRemoved Activate");            }            else if (variable == "SrdLowerPanelRemoved" && (bool)value == true)            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "SrdLowerPanelRemoved Activate");            }            else if (variable == "PlumbingDoorClosed" && (bool)value == false) //信号是反的            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "PlumbingDoorClosed Activate");            }            else if (variable == "ProcessUpperPanelsOn" && (bool)value == false) //信号是反的            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "ProcessUpperPanelsOn Activate");            }            else if (variable == "PumpEdm" && (bool)value == false) //信号是反的            {                LOG.WriteLog(eEvent.ERR_SAFETY, Module, "PumpEdm Activate");            }        }        #endregion                #region SLS        /// <summary>        /// SLS更改速度        /// </summary>        /// <param name="variable"></param>        /// <param name="sls"></param>        private void SlsChangedSpeed(string variable,bool sls)        {            int slsSpeed = SC.GetValue<int>("Twincat.SlsSpeed");            if(sls)            {                ModuleChangeSpeed(variable, slsSpeed);            }            else            {                ModuleChangeSpeed(variable, 100);            }        }        /// <summary>        /// 模块更改速度        /// </summary>        /// <param name="variable"></param>        /// <param name="percent"></param>        private void ModuleChangeSpeed(string variable,int percent)        {            switch(variable)            {                case PUF1_VERTICAL_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF1}.Vertical"), percent);                    break;                case PUF2_VERTICAL_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF2}.Vertical"), percent);                    break;                case LOADER_TILTA_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltA"), percent);                    break;                case LOADER_TILTB_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.TiltB"), percent);                    break;                case LOADER_SWINGA_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.ShuttleA"), percent);                    break;                case LOADER_SWINGB_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.ShuttleB"), percent);                    break;                case LOADER_ROTATION_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Rotation"), percent);                    break;                case LOADER_GANTRY_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Gantry"), percent);                    break;                case LOADER_ELEVATOR_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter2}.Elevator"), percent);                    break;                case PROCESS_GANTRY_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter1}.Gantry"), percent);                    break;                case PROCESS_ELEVATOR_SLS:                    UpdateAxisSpeed(DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Transporter1}.Elevator"), percent);                    break;            }        }        /// <summary>        /// 更改Axis速度百分比        /// </summary>        /// <param name="jetAxisBase"></param>        /// <param name="percent"></param>        private void UpdateAxisSpeed(JetAxisBase jetAxisBase,int percent)        {            jetAxisBase.ChangePercentSpeedAceleration(percent);        }        #endregion        #region Reset        /// <summary>        /// Reset Operation        /// </summary>        /// <returns></returns>        private bool ResetOperation()        {            _status = _resetRoutine.Start();            return _status == RState.Running;        }        #endregion        #region All On        /// <summary>        /// All On Operation        /// </summary>        /// <returns></returns>        private bool AllOnOperation()        {            _allOnStatus = _allOnRoutine.Start();            return _allOnStatus == RState.Running;        }        #endregion        #region Lock Door        /// <summary>        /// Lock Process Door        /// </summary>        /// <returns></returns>        public bool LockProcessDoor()        {            string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PROCESS_DOOR_LOCK}");            return IOModuleManager.Instance.WriteIoValue(ioName, true);        }        /// <summary>        /// Unlock Process Door        /// </summary>        /// <returns></returns>        public bool UnlockProcessDoor()        {            string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{PROCESS_DOOR_LOCK}");            return IOModuleManager.Instance.WriteIoValue(ioName, false);        }        /// <summary>        /// Lock Buffer Door        /// </summary>        /// <returns></returns>        public bool LockBufferDoor()        {            string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{BUFFER_DOOR_LOCK}");            return IOModuleManager.Instance.WriteIoValue(ioName, true);        }        /// <summary>        /// Unlock Buffer Door        /// </summary>        /// <returns></returns>        public bool UnlockBufferDoor()        {            string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{BUFFER_DOOR_LOCK}");            return IOModuleManager.Instance.WriteIoValue(ioName, false);        }        /// <summary>        /// Lock Loader Door        /// </summary>        /// <returns></returns>        public bool LockLoaderDoor()        {            string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{LOADER_DOOR_LOCK}");            return IOModuleManager.Instance.WriteIoValue(ioName, true);        }        /// <summary>        /// Unlock Loader Door        /// </summary>        /// <returns></returns>        public bool UnlockLoaderDoor()        {            string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{LOADER_DOOR_LOCK}");            return IOModuleManager.Instance.WriteIoValue(ioName, false);        }        #endregion        #region Mode Siren         /// <summary>        /// Mode Siren On        /// </summary>        /// <returns></returns>        public bool ModeSirenOn()        {            if (!SafetyData.ModeSiren)            {                string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{MODE_SIREN}");                return IOModuleManager.Instance.WriteIoValue(ioName, true);            }            return true;        }        /// <summary>        /// Mode Siren Off        /// </summary>        /// <returns></returns>        public bool ModeSirenOff()        {            if (SafetyData.ModeSiren)            {                string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{MODE_SIREN}");                return IOModuleManager.Instance.WriteIoValue(ioName, false);            }            return true;        }        #endregion        public void Monitor()        {        }        public void Reset()        {        }        public void Terminate()        {            _periodicJob.Stop(false);        }    }}
 |