using Amqp;
using CFX;
using CFX.ResourcePerformance;
using CFX.Structures;
using HslCommunication;
using Sln.Iot.Business.Entity;
using Sln.Iot.CFX.CFXConnect;
using Sln.Iot.CFX.Event;
using Sln.Iot.Config;
using Sln.Iot.PLC;
using Sln.Iot.Repository.dao;
using Sln.Iot.Repository.service;
using Sln.Iot.Serilog;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;

namespace Sln.Iot.Business
{
    public class ErrorAnalyseBusiness
    {
        private Timer _timer;

        private readonly PLCConnect _plc = PLCConnect.Instance;
        private readonly SerilogHelper _log = SerilogHelper.Instance;
        private readonly AppConfig _appConfig = AppConfigSetting.Load();

        private readonly ErrorService errorService = ErrorService.Instance;
        private readonly TrayBindingService trayBindingService = TrayBindingService.Instance;

        private FaultOccurredEvent faultOccurredEvent = new FaultOccurredEvent();
        private FaultClearedEvent faultClearedEvent = new FaultClearedEvent();

        private CFXConnectOven CFXOven = CFXConnectOven.Instance;
        private CFXConnectVacuum CFXVacuum = CFXConnectVacuum.Instance;

        public ErrorAnalyseBusiness()
        {
            _timer = new Timer(TimerCallback, null, 0, 3000);
        }

        /// <summary>
        /// 报警点位刷新
        /// </summary>
        /// <param name="state"></param>
        public void TimerCallback(object? state)
        {
            try
            {
                // 烤箱报警 D100（1个字）— PLC20（192.168.1.20）
                var result20 = _plc.ReadBytes(_plc.PLC20, "D100", 1);
                // 真空灌胶机报警 D100-D105（6个字）— PLC21（192.168.1.21）
                var result21 = _plc.ReadBytes(_plc.PLC21, "D100", 6);

                if (result20.IsSuccess && result20.Content != null)
                {
                    BitArray bits20 = new BitArray(ToolBusiness.SwapAdjacentBytes(result20.Content));
                    bool[] bools20 = new bool[bits20.Count];
                    bits20.CopyTo(bools20, 0);
                    OvenAlarmAnalyse(bools20);
                }

                if (result21.IsSuccess && result21.Content != null)
                {
                    BitArray bits21 = new BitArray(ToolBusiness.SwapAdjacentBytes(result21.Content));
                    bool[] bools21 = new bool[bits21.Count];
                    bits21.CopyTo(bools21, 0);
                    VacuumAlarmAnalyse(bools21);
                }
            }
            catch (Exception ex)
            {
                _log.Error("报警信息处理发生错误", ex);
            }
        }

        /// <summary>
        /// 真空灌胶机报警分析
        /// </summary>
        /// <param name="bools"></param>
        public void VacuumAlarmAnalyse(bool[] bools)
        {
            //现存的错误数据
            List<Vacuum1Error>? errorList = errorService.GetV1List();

            foreach (var errorMessage in VacuumAlarms)
            {
                if (errorMessage.ErrorIndex < bools.Length && bools[errorMessage.ErrorIndex])
                {
                    //如果原来没有 现在有 添加错误
                    if (errorList.Count(x => x.ErrorName == errorMessage.ENAlarmMessage) == 0)
                    {
                        Guid.TryParse(trayBindingService.TidGet(), out Guid transID);
                        Guid logGuid = Guid.NewGuid();
                        errorService.InsertVacuum1Error(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
                        CFXVacuum.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage, transID)));
                        if (_appConfig.IsAlarmLog)
                            _log.Info($"真空灌胶机报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
                    }
                }
                else
                {
                    //如果原来有 现在没有 则删除
                    if (errorList.Count(x => x.ErrorName == errorMessage.ENAlarmMessage) != 0)
                    {
                        //删除错误
                        string delGuid = errorService.DeleteVacuum1Error(errorMessage.ENAlarmMessage);
                        Guid.TryParse(delGuid, out Guid guidRes);
                        CFXVacuum.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
                        if (_appConfig.IsAlarmLog)
                            _log.Info($"真空灌胶机报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
                    }
                }
            }
        }

        

        /// <summary>
        /// 烤箱报警分析
        /// </summary>
        /// <param name="bools"></param>
        public void OvenAlarmAnalyse(bool[] bools)
        {
            //现存的错误数据
            List<OvenError>? errorList = errorService.GetOvenList();

            foreach (var errorMessage in OvenAlarms)
            {
                if (bools[errorMessage.ErrorIndex])
                {
                    //如果原来没有 现在有 添加错误
                    if (errorList.Count(x => x.ErrorName == errorMessage.ENAlarmMessage) == 0)
                    {
                        Guid.TryParse(trayBindingService.TidGet(), out Guid transID);
                        Guid logGuid = Guid.NewGuid();
                        errorService.InsertOvenError(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
                        CFXOven.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage, transID)));
                        if (_appConfig.IsAlarmLog)
                            _log.Info($"烤箱报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
                    }
                }
                else
                {
                    //如果原来有 现在没有 则删除
                    if (errorList.Count(x => x.ErrorName == errorMessage.ENAlarmMessage) != 0)
                    {
                        //删除错误
                        string delGuid = errorService.DeleteOvenError(errorMessage.ENAlarmMessage);
                        Guid.TryParse(delGuid, out Guid guidRes);
                        CFXOven.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
                        if (_appConfig.IsAlarmLog)
                            _log.Info($"烤箱报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
                    }
                }
            }
        }



        /// <summary>
        /// 报警等级转换
        /// </summary>
        /// <returns></returns>
        private FaultSeverity LevelTrans(AlarmDegardeEnum alarmDegardeEnum)
        {
            switch (alarmDegardeEnum)
            {
                case AlarmDegardeEnum.Warning:
                    return FaultSeverity.Information;
                case AlarmDegardeEnum.Error:
                    return FaultSeverity.Warning;
                case AlarmDegardeEnum.Fault:
                    return FaultSeverity.Error;
                default:
                    return FaultSeverity.Information;
            }
        }


        /// <summary>
        /// 真空灌胶机报警定义（PLC21 D100-D105，6字=96位）
        /// </summary>
        public static readonly List<AlarmMessageEntity> VacuumAlarms = new()
        {
            // ===== D100（位偏移 0-15）=====
            new() { ErrorIndex = 0, ENAlarmMessage = "AntiCuring time up!", CNAlarmMessage = "防固时间到！", AlarmDegarde = AlarmDegardeEnum.Warning, ErrorCode = "100" },
            new() { ErrorIndex = 1, ENAlarmMessage = "Tank A Upper limit!", CNAlarmMessage = "A桶上限报警", AlarmDegarde = AlarmDegardeEnum.Warning, ErrorCode = "101" },
            new() { ErrorIndex = 2, ENAlarmMessage = "Tank A Lower limit!", CNAlarmMessage = "A桶下限报警", AlarmDegarde = AlarmDegardeEnum.Warning, ErrorCode = "102" },
            new() { ErrorIndex = 3, ENAlarmMessage = "Tank B Upper limit!", CNAlarmMessage = "B桶上限报警", AlarmDegarde = AlarmDegardeEnum.Warning, ErrorCode = "103" },
            new() { ErrorIndex = 4, ENAlarmMessage = "Tank B Lower limit!", CNAlarmMessage = "B桶下限报警", AlarmDegarde = AlarmDegardeEnum.Warning, ErrorCode = "104" },

            // ===== D102（位偏移 32-47）=====
            new() { ErrorIndex = 32 + 0, ENAlarmMessage = "Glue tank Vacuum Motor Error!", CNAlarmMessage = "料桶真空泵报警！", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "105" },
            new() { ErrorIndex = 32 + 1, ENAlarmMessage = "Pump A Backward Limit Reached!", CNAlarmMessage = "泵A负限位报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "106" },
            new() { ErrorIndex = 32 + 2, ENAlarmMessage = "Pump A Forward Limit Reached!", CNAlarmMessage = "泵A正限位报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "107" },
            new() { ErrorIndex = 32 + 3, ENAlarmMessage = "Pump B Backward Limit Reached!", CNAlarmMessage = "泵B负限报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "108" },
            new() { ErrorIndex = 32 + 4, ENAlarmMessage = "Pump B Forward Limit Reached!", CNAlarmMessage = "泵B正限禁止", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "109" },
            new() { ErrorIndex = 32 + 5, ENAlarmMessage = "Servo A Error!", CNAlarmMessage = "泵A伺服报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "110" },
            new() { ErrorIndex = 32 + 6, ENAlarmMessage = "Servo B Error!", CNAlarmMessage = "泵B伺服报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "111" },

            // ===== D104（位偏移 64-79）=====
            new() { ErrorIndex = 64 + 0, ENAlarmMessage = "Mixing Valve Open Error!", CNAlarmMessage = "混合阀打开异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "200" },
            new() { ErrorIndex = 64 + 1, ENAlarmMessage = "Inlet Valve of Pump A Close Error!", CNAlarmMessage = "A泵进胶阀关异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "201" },
            new() { ErrorIndex = 64 + 2, ENAlarmMessage = "Outlet Valve of Pump A Close Error!", CNAlarmMessage = "A泵出胶阀关异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "202" },
            new() { ErrorIndex = 64 + 3, ENAlarmMessage = "Inlet Valve of Pump A Open Error!", CNAlarmMessage = "A泵进胶阀打开异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "203" },
            new() { ErrorIndex = 64 + 4, ENAlarmMessage = "Outlet Valve of Pump A Open Error!", CNAlarmMessage = "A泵出胶阀打开异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "204" },
            new() { ErrorIndex = 64 + 5, ENAlarmMessage = "Inlet Valve of Pump B Close Error!", CNAlarmMessage = "B泵进胶阀关异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "205" },
            new() { ErrorIndex = 64 + 6, ENAlarmMessage = "Outlet Valve of Pump B Close Error!", CNAlarmMessage = "B泵出胶阀关异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "206" },
            new() { ErrorIndex = 64 + 7, ENAlarmMessage = "Inlet Valve of Pump B Open Error!", CNAlarmMessage = "B进胶阀打开异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "207" },
            new() { ErrorIndex = 64 + 8, ENAlarmMessage = "Outlet Valve of Pump B Open Error!", CNAlarmMessage = "B出胶阀打开异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "208" },
            new() { ErrorIndex = 64 + 9, ENAlarmMessage = "Globe Valve of Tank A Open Error!", CNAlarmMessage = "A桶球阀打开异常！", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "209" },
            new() { ErrorIndex = 64 + 10, ENAlarmMessage = "Globe Valve of Tank B Open Error!", CNAlarmMessage = "B桶球阀打开异常！", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "210" },
            new() { ErrorIndex = 64 + 11, ENAlarmMessage = "Pump A Pressure Over UpperLimit", CNAlarmMessage = "A泵压力上限报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "211" },
            new() { ErrorIndex = 64 + 12, ENAlarmMessage = "Pump B Pressure Over UpperLimit", CNAlarmMessage = "B泵压力上限报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "212" },
            new() { ErrorIndex = 64 + 13, ENAlarmMessage = "Air Pressure Alarm", CNAlarmMessage = "系统气压报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "213" },

            // ===== D105（位偏移 80-95）=====
            new() { ErrorIndex = 80 + 0, ENAlarmMessage = "Axis X Servo error", CNAlarmMessage = "X轴伺服报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "112" },
            new() { ErrorIndex = 80 + 1, ENAlarmMessage = "Axis Y Servo error", CNAlarmMessage = "Y轴伺服报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "113" },
            new() { ErrorIndex = 80 + 2, ENAlarmMessage = "Axis Z Servo error", CNAlarmMessage = "Z轴伺服报警", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "114" },
            new() { ErrorIndex = 80 + 3, ENAlarmMessage = "Vacuum Tank Vacuum Pump Error", CNAlarmMessage = "真空箱真空泵异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "115" },
            new() { ErrorIndex = 80 + 4, ENAlarmMessage = "VacuumChamber Vacuum Valve Error", CNAlarmMessage = "真空箱真空阀打开异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "214" },
            new() { ErrorIndex = 80 + 5, ENAlarmMessage = "Vacuum Vent Valve Close Error", CNAlarmMessage = "真空箱放气阀关闭异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "215" },
            new() { ErrorIndex = 80 + 6, ENAlarmMessage = "Vacuum Chamber Lifter error", CNAlarmMessage = "灌胶定位缸异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "216" },
            new() { ErrorIndex = 80 + 7, ENAlarmMessage = "Vacuum Chamber Inlet Door Open error", CNAlarmMessage = "1号真空箱入口门打开异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "216" },
            new() { ErrorIndex = 80 + 8, ENAlarmMessage = "Vacuum Chamber Inlet Door Close error", CNAlarmMessage = "1号真空箱入口门关闭异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "216" },
            new() { ErrorIndex = 80 + 9, ENAlarmMessage = "Vacuum Chamber Outlet Door Open error", CNAlarmMessage = "1号真空箱出口门打开异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "216" },
            new() { ErrorIndex = 80 + 10, ENAlarmMessage = "Vacuum Chamber Outlet Door Close error", CNAlarmMessage = "1号真空箱出口门关闭异常", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "216" },
            new() { ErrorIndex = 80 + 11, ENAlarmMessage = "RFID1 Read Error", CNAlarmMessage = "RFID1读失败", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "116" },
            new() { ErrorIndex = 80 + 13, ENAlarmMessage = "Front Door Not closed.", CNAlarmMessage = "箱前门没有关闭。", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "117" },
            new() { ErrorIndex = 80 + 14, ENAlarmMessage = "Inlet Door LightCurtain Warning", CNAlarmMessage = "入口光栅触发", AlarmDegarde = AlarmDegardeEnum.Warning, ErrorCode = "118" },
            new() { ErrorIndex = 80 + 15, ENAlarmMessage = "Outlet Door LightCurtain Warning", CNAlarmMessage = "出口光栅触发", AlarmDegarde = AlarmDegardeEnum.Warning, ErrorCode = "119" },
        };

        /// <summary>
        /// 烤箱报警定义（PLC20 D100，1字=16位）
        /// </summary>
        public static readonly List<AlarmMessageEntity> OvenAlarms = new()
        {
            new() { ErrorIndex = 0, ENAlarmMessage = "Line E.Stop ON!", CNAlarmMessage = "线急停按下！", AlarmDegarde = AlarmDegardeEnum.Warning, ErrorCode = "11" },
            new() { ErrorIndex = 1, ENAlarmMessage = "Curing Zone I heating error!", CNAlarmMessage = "固化1区加热异常！", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "12" },
            new() { ErrorIndex = 2, ENAlarmMessage = "Curing Zone II heating error!", CNAlarmMessage = "固化2区加热异常！", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "18" },
            new() { ErrorIndex = 3, ENAlarmMessage = "RFID2 Read Error", CNAlarmMessage = "RFID2读码错误", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "20" },
            new() { ErrorIndex = 4, ENAlarmMessage = "RFID3 Read Error", CNAlarmMessage = "RFID3读码错误", AlarmDegarde = AlarmDegardeEnum.Error, ErrorCode = "22" },
        };

        ///// <summary>
        ///// 真空箱报警定义（旧）
        ///// </summary>
        //public static readonly List<AlarmMessageEntity> VacuumAlarms_Old = new()
        //{
        //    new() { ErrorIndex = 16 * 0 + 0, ENAlarmMessage = "1# Pump A Backward Limit Reached!", CNAlarmMessage = "泵A负限超程！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 1, ENAlarmMessage = "1# Pump A Forward Limit Reached!", CNAlarmMessage = "泵A正限超程！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 2, ENAlarmMessage = "1# Pump B Backward Limit Reached!", CNAlarmMessage = "泵B负限超程！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 3, ENAlarmMessage = "1# Pump B Forward Limit Reached!", CNAlarmMessage = "泵B正限超程！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 4, ENAlarmMessage = "1# Servo A Error!", CNAlarmMessage = "泵A伺服报警！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 5, ENAlarmMessage = "1# Servo B Error!", CNAlarmMessage = "泵B伺服报警！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 6, ENAlarmMessage = "Mixed Servo Error!", CNAlarmMessage = "混合伺服报警！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 7, ENAlarmMessage = "Mixed Motor Rotating Error!", CNAlarmMessage = "混合电机旋转异常！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 12, ENAlarmMessage = "A1 Heating Error", CNAlarmMessage = "A1加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 13, ENAlarmMessage = "B1 Heating Error", CNAlarmMessage = "B1加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 14, ENAlarmMessage = "A2 Heating Error", CNAlarmMessage = "A2加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 15, ENAlarmMessage = "B2 Heating Error", CNAlarmMessage = "B2加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 1 + 0, ENAlarmMessage = "A Potting Valve Open Error", CNAlarmMessage = "A吐出阀打开异常", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 1 + 1, ENAlarmMessage = "B Potting Valve Open Error", CNAlarmMessage = "B吐出阀打开异常", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 2 + 0, ENAlarmMessage = "1# Tank A Globe Valve Error!", CNAlarmMessage = "A1桶球阀打开异常！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 2 + 1, ENAlarmMessage = "1# Tank B Globe Valve Error!", CNAlarmMessage = "B1桶球阀打开异常！", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 2 + 2, ENAlarmMessage = "Vacuum Chamber Inlet Door Open Error", CNAlarmMessage = "真空箱入口门打开异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 2 + 3, ENAlarmMessage = "Vacuum Chamber Inlet Door Close Error", CNAlarmMessage = "真空箱入口门关闭异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 2 + 4, ENAlarmMessage = "Vacuum Chamber Outlet Door Open Error", CNAlarmMessage = "真空箱出口门打开异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 2 + 5, ENAlarmMessage = "Vacuum Chamber Outlet Door Close Error", CNAlarmMessage = "真空箱出口门关闭异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 2 + 8, ENAlarmMessage = "Axis X Servo Error", CNAlarmMessage = "X轴伺服报警", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 2 + 9, ENAlarmMessage = "Axis Y Servo Error", CNAlarmMessage = "Y轴伺服报警", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 2 + 10, ENAlarmMessage = "Axis Z Servo Error", CNAlarmMessage = "Z轴伺服报警", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 2 + 11, ENAlarmMessage = "Vacuum Tank Vacuum Pump Error", CNAlarmMessage = "真空箱真空泵异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 2 + 12, ENAlarmMessage = "Vacuum Chamber Lifter Error", CNAlarmMessage = "灌胶定位缸异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 2 + 13, ENAlarmMessage = "Vacuum Chamber Vacuum Valve Error", CNAlarmMessage = "真空阀打开异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 2 + 14, ENAlarmMessage = "Vacuum Vent Valve Close Error", CNAlarmMessage = "放气阀关闭异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 3 + 0, ENAlarmMessage = "Air Pressure Alarm", CNAlarmMessage = "系统气压报警", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 3 + 2, ENAlarmMessage = "Glue Tank Vacuum Pump Error!", CNAlarmMessage = "料桶真空泵报警！", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 4 + 0, ENAlarmMessage = "Pump A Pressure Over Upper Limit", CNAlarmMessage = "A泵压力上限报警", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 4 + 1, ENAlarmMessage = "Pump A Pressure Below Lower Limit", CNAlarmMessage = "A泵压力下限报警", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 4 + 2, ENAlarmMessage = "Pump B Pressure Over Upper Limit", CNAlarmMessage = "B泵压力上限报警", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 4 + 3, ENAlarmMessage = "Pump B Pressure Below Lower Limit", CNAlarmMessage = "B泵压力下限报警", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 10 + 0, ENAlarmMessage = "1# Tank A Upper Limit!", CNAlarmMessage = "A1桶上限报警！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 1, ENAlarmMessage = "1# Tank A Lower Limit!", CNAlarmMessage = "A1桶下限报警！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 2, ENAlarmMessage = "1# Tank B Upper Limit!", CNAlarmMessage = "B1桶上限报警！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 3, ENAlarmMessage = "1# Tank B Lower Limit!", CNAlarmMessage = "B1桶下限报警！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 4, ENAlarmMessage = "2# Tank A Upper Limit!", CNAlarmMessage = "A2桶上限报警！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 5, ENAlarmMessage = "2# Tank A Lower Limit!", CNAlarmMessage = "A2桶下限报警！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 6, ENAlarmMessage = "2# Tank B Upper Limit!", CNAlarmMessage = "B2桶上限报警！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 7, ENAlarmMessage = "2# Tank B Lower Limit!", CNAlarmMessage = "B2桶下限报警！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 8, ENAlarmMessage = "1# Antisolid Time Up!", CNAlarmMessage = "防固时间到！", AlarmDegarde = AlarmDegardeEnum.Warning },
        //    new() { ErrorIndex = 16 * 10 + 9, ENAlarmMessage = "Globe Valve Not Opened!", CNAlarmMessage = "球阀未打开！", AlarmDegarde = AlarmDegardeEnum.Error },
        //};



        ///// <summary>
        ///// 加热线报警定义（旧）
        ///// </summary>
        //public static readonly List<AlarmMessageEntity> OvenAlarms_Old = new()
        //{
        //    new() { ErrorIndex = 16 * 0 + 0, ENAlarmMessage = "Line E.Stop ON!", CNAlarmMessage = "线急停按下", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 1, ENAlarmMessage = "Preheating Zone Heating Error!", CNAlarmMessage = "预热区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 2, ENAlarmMessage = "Precuring Zone I Heating Error!", CNAlarmMessage = "预固1区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 3, ENAlarmMessage = "Precuring Zone II Heating Error!", CNAlarmMessage = "预固2区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 4, ENAlarmMessage = "Precuring Zone III Heating Error!", CNAlarmMessage = "预固3区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 5, ENAlarmMessage = "Precuring Zone IV Heating Error!", CNAlarmMessage = "预固4区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 6, ENAlarmMessage = "Curing Zone I Heating Error!", CNAlarmMessage = "固化1区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 7, ENAlarmMessage = "Curing Zone II Heating Error!", CNAlarmMessage = "固化2区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 8, ENAlarmMessage = "Curing Zone III Heating Error!", CNAlarmMessage = "固化3区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //    new() { ErrorIndex = 16 * 0 + 9, ENAlarmMessage = "Curing Zone IV Heating Error!", CNAlarmMessage = "固化4区加热异常", AlarmDegarde = AlarmDegardeEnum.Error },
        //};

        ///// <summary>
        ///// 提升机报警定义
        ///// </summary>
        //public static readonly List<AlarmMessageEntity> LiftAlarms = new()
        //{
        //    new() { ErrorIndex = 16 * 0 + 0, ENAlarmMessage = "Loading Lifter Down Error", CNAlarmMessage = "上料提升机下降异常", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 1, ENAlarmMessage = "Loading Lifter Up Error", CNAlarmMessage = "上料提升机上升异常", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 2, ENAlarmMessage = "Loading Lifter E.Stop Pressed", CNAlarmMessage = "上料提升机急停按下", AlarmDegarde = AlarmDegardeEnum.Fault },

        //    new() { ErrorIndex = 16 * 0 + 3, ENAlarmMessage = "Unloading Lifter Down Error", CNAlarmMessage = "下料提升机下降异常", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 4, ENAlarmMessage = "Unloading Lifter Up Error", CNAlarmMessage = "下料提升机上升异常", AlarmDegarde = AlarmDegardeEnum.Fault },
        //    new() { ErrorIndex = 16 * 0 + 5, ENAlarmMessage = "Unloading Lifter E.Stop Pressed", CNAlarmMessage = "下料提升机急停按下", AlarmDegarde = AlarmDegardeEnum.Fault },
        //};



        ///// <summary>
        ///// 真空注胶机1解析
        ///// </summary>
        ///// <param name="boolIndex"></param>
        ///// <returns></returns>
        //public static AlarmMessageEntity? GetVacuum1AlarmMessage(int boolIndex)
        //{
        //    switch (boolIndex)
        //    {
        //        // ===== D80 =====
        //        case 16 * 0 + 0: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 0, ENAlarmMessage = "1# Pump A Backward Limit Reached!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 1: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 1, ENAlarmMessage = "1# Pump A Forward Limit Reached!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 2: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 2, ENAlarmMessage = "1# Pump B Backward Limit Reached!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 3: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 3, ENAlarmMessage = "1# Pump B Forward Limit Reached!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 4: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 4, ENAlarmMessage = "1# Servo A Error!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 5: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 5, ENAlarmMessage = "1# Servo B Error!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 6: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 6, ENAlarmMessage = "Mixed Servo Error!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 7: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 7, ENAlarmMessage = "Mixed Motor Rotating Error!", AlarmDegarde = AlarmDegardeEnum.Fault };

        //        case 16 * 0 + 12: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 12, ENAlarmMessage = "A1 Heating Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 13: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 13, ENAlarmMessage = "B1 Heating Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 14: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 14, ENAlarmMessage = "A2 Heating Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 15: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 15, ENAlarmMessage = "B2 Heating Error", AlarmDegarde = AlarmDegardeEnum.Error };

        //        // ===== D81 =====
        //        case 16 * 1 + 0: return new AlarmMessageEntity { ErrorIndex = 16 * 1 + 0, ENAlarmMessage = "A Potting Valve Open Error", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 1 + 1: return new AlarmMessageEntity { ErrorIndex = 16 * 1 + 1, ENAlarmMessage = "B Potting Valve Open Error", AlarmDegarde = AlarmDegardeEnum.Fault };

        //        // ===== D82 =====
        //        case 16 * 2 + 0: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 0, ENAlarmMessage = "1# Tank A Globe Valve Error!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 2 + 1: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 1, ENAlarmMessage = "1# Tank B Globe Valve Error!", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 2 + 2: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 2, ENAlarmMessage = "1# Vacuum Chamber Inlet Door Open Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 2 + 3: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 3, ENAlarmMessage = "1# Vacuum Chamber Inlet Door Close Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 2 + 4: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 4, ENAlarmMessage = "1# Vacuum Chamber Outlet Door Open Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 2 + 5: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 5, ENAlarmMessage = "1# Vacuum Chamber Outlet Door Close Error", AlarmDegarde = AlarmDegardeEnum.Error };

        //        case 16 * 2 + 8: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 8, ENAlarmMessage = "Axis X Servo Error", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 2 + 9: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 9, ENAlarmMessage = "Axis Y Servo Error", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 2 + 10: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 10, ENAlarmMessage = "Axis Z Servo Error", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 2 + 11: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 11, ENAlarmMessage = "Vacuum Tank Vacuum Pump Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 2 + 12: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 12, ENAlarmMessage = "Vacuum Chamber Lifter Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 2 + 13: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 13, ENAlarmMessage = "Vacuum Chamber Vacuum Valve Error", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 2 + 14: return new AlarmMessageEntity { ErrorIndex = 16 * 2 + 14, ENAlarmMessage = "Vacuum Vent Valve Close Error", AlarmDegarde = AlarmDegardeEnum.Error };

        //        // ===== D83 =====
        //        case 16 * 3 + 0: return new AlarmMessageEntity { ErrorIndex = 16 * 3 + 0, ENAlarmMessage = "Air Pressure Alarm", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 3 + 2: return new AlarmMessageEntity { ErrorIndex = 16 * 3 + 2, ENAlarmMessage = "Glue Tank Vacuum Pump Error!", AlarmDegarde = AlarmDegardeEnum.Error };

        //        // ===== D84 =====
        //        case 16 * 4 + 0: return new AlarmMessageEntity { ErrorIndex = 16 * 4 + 0, ENAlarmMessage = "Pump A Pressure Over Upper Limit", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 4 + 1: return new AlarmMessageEntity { ErrorIndex = 16 * 4 + 1, ENAlarmMessage = "Pump A Pressure Below Lower Limit", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 4 + 2: return new AlarmMessageEntity { ErrorIndex = 16 * 4 + 2, ENAlarmMessage = "Pump B Pressure Over Upper Limit", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 4 + 3: return new AlarmMessageEntity { ErrorIndex = 16 * 4 + 3, ENAlarmMessage = "Pump B Pressure Below Lower Limit", AlarmDegarde = AlarmDegardeEnum.Fault };

        //        // ===== D90 =====
        //        case 16 * 10 + 0: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 0, ENAlarmMessage = "1# Tank A Upper Limit!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 1: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 1, ENAlarmMessage = "1# Tank A Lower Limit!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 2: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 2, ENAlarmMessage = "1# Tank B Upper Limit!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 3: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 3, ENAlarmMessage = "1# Tank B Lower Limit!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 4: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 4, ENAlarmMessage = "2# Tank A Upper Limit!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 5: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 5, ENAlarmMessage = "2# Tank A Lower Limit!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 6: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 6, ENAlarmMessage = "2# Tank B Upper Limit!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 7: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 7, ENAlarmMessage = "2# Tank B Lower Limit!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 8: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 8, ENAlarmMessage = "1# Antisolid Time Up!", AlarmDegarde = AlarmDegardeEnum.Warning };
        //        case 16 * 10 + 9: return new AlarmMessageEntity { ErrorIndex = 16 * 10 + 9, ENAlarmMessage = "Globe Valve Not Opened!", AlarmDegarde = AlarmDegardeEnum.Error };

        //        default:
        //            return null;
        //    }
        //}

        ///// <summary>
        ///// 加热线警报
        ///// </summary>
        ///// <param name="boolIndex"></param>
        ///// <returns></returns>
        //public static AlarmMessageEntity? GetHeatingLineAlarm(int boolIndex)
        //{
        //    switch (boolIndex)
        //    {
        //        // ===== D100 =====
        //        case 16 * 0 + 0: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 0, ENAlarmMessage = "Line E.Stop ON!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 1: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 1, ENAlarmMessage = "Preheating Zone Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 2: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 2, ENAlarmMessage = "Precuring Zone I Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 3: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 3, ENAlarmMessage = "Precuring Zone II Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 4: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 4, ENAlarmMessage = "Precuring Zone III Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 5: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 5, ENAlarmMessage = "Precuring Zone IV Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 6: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 6, ENAlarmMessage = "Curing Zone I Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 7: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 7, ENAlarmMessage = "Curing Zone II Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 8: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 8, ENAlarmMessage = "Curing Zone III Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 9: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 9, ENAlarmMessage = "Curing Zone IV Heating Error!", AlarmDegarde = AlarmDegardeEnum.Error };

        //        default:
        //            return null;
        //    }
        //}

        ///// <summary>
        ///// 提升机警报
        ///// </summary>
        ///// <param name="boolIndex"></param>
        ///// <returns></returns>
        //public static AlarmMessageEntity? GetLifterAlarm(int boolIndex)
        //{
        //    switch (boolIndex)
        //    {
        //        // ===== D100 =====
        //        case 16 * 0 + 0: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 0, ENAlarmMessage = "Loading Lifter Down Error", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 1: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 1, ENAlarmMessage = "Loading Lifter Up Error", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 2: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 2, ENAlarmMessage = "Loading Lifter E.Stop Pressed", AlarmDegarde = AlarmDegardeEnum.Error };
        //        case 16 * 0 + 3: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 3, ENAlarmMessage = "Unloading Lifter Down Error", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 4: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 4, ENAlarmMessage = "Unloading Lifter Up Error", AlarmDegarde = AlarmDegardeEnum.Fault };
        //        case 16 * 0 + 5: return new AlarmMessageEntity { ErrorIndex = 16 * 0 + 5, ENAlarmMessage = "Unloading Lifter E.Stop Pressed", AlarmDegarde = AlarmDegardeEnum.Error };

        //        default:
        //            return null;
        //    }
        //}

        ///// <summary>
        ///// 真空箱1报警分析（旧）
        ///// </summary>
        //public void VacuumAlarm1Analyse(bool[] bools)
        //{
        //    List<Vacuum1Error>? errorList = errorService.GetV1List();
        //    foreach (var errorMessage in VacuumAlarms_Old)
        //    {
        //        if (bools[errorMessage.ErrorIndex])
        //        {
        //            if (errorList.Where(x => x.ErrorName == errorMessage.ENAlarmMessage).Count() == 0)
        //            {
        //                Guid.TryParse(trayBindingService.TidGet(), out Guid transID);
        //                Guid logGuid = Guid.NewGuid();
        //                errorService.InsertVacuum1Error(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
        //                connect1.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage + "-Vacuum1", transID)));
        //                if (_appConfig.IsAlarmLog)
        //                    _log.Info($"真空箱1报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
        //            }
        //        }
        //        else
        //        {
        //            if (errorList.Where(x => x.ErrorName == errorMessage.ENAlarmMessage).Count() != 0)
        //            {
        //                string delGuid = errorService.DeleteVacuum1Error(errorMessage.ENAlarmMessage);
        //                Guid.TryParse(delGuid, out Guid guidRes);
        //                connect1.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
        //                if (_appConfig.IsAlarmLog)
        //                    _log.Info($"真空箱1报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
        //            }
        //        }
        //    }
        //}

        ///// <summary>
        ///// 真空箱2报警分析（旧）
        ///// </summary>
        //public void VacuumAlarm2Analyse(bool[] bools)
        //{
        //    List<Vacuum2Error>? errorList = errorService.GetV2List();
        //    foreach (var errorMessage in VacuumAlarms_Old)
        //    {
        //        if (bools[errorMessage.ErrorIndex])
        //        {
        //            if (errorList.Where(x => x.ErrorName == errorMessage.ENAlarmMessage).Count() == 0)
        //            {
        //                Guid.TryParse(trayBindingService.TidGet(), out Guid transID);
        //                Guid logGuid = Guid.NewGuid();
        //                errorService.InsertVacuum2Error(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
        //                connect1.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage + "-Vacuum2", transID)));
        //                if (_appConfig.IsAlarmLog)
        //                    _log.Info($"真空箱2报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
        //            }
        //        }
        //        else
        //        {
        //            if (errorList.Where(x => x.ErrorName == errorMessage.ENAlarmMessage).Count() != 0)
        //            {
        //                string delGuid = errorService.DeleteVacuum2Error(errorMessage.ENAlarmMessage);
        //                Guid.TryParse(delGuid, out Guid guidRes);
        //                connect1.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
        //                if (_appConfig.IsAlarmLog)
        //                    _log.Info($"真空箱2报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
        //            }
        //        }
        //    }
        //}

        ///// <summary>
        ///// 提升机报警分析
        ///// </summary>
        ///// <param name="bools"></param>
        //public void LiftAlarmAnalyse(bool[] bools)
        //{
        //    //现存的错误数据
        //    List<LiftError>? errorList = errorService.GetLiftList();

        //    foreach (var errorMessage in LiftAlarms)
        //    {
        //        if (bools[errorMessage.ErrorIndex])
        //        {
        //            //如果原来没有 现在有 添加错误
        //            if (errorList.Where(x => x.ErrorName == errorMessage.ENAlarmMessage).Count() == 0)
        //            {
        //                Guid.TryParse(trayBindingService.TidGet(), out Guid transID);
        //                Guid logGuid = Guid.NewGuid();
        //                errorService.InsertLiftError(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
        //                CFXOven.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage, transID)));
        //                if (_appConfig.IsAlarmLog)
        //                    _log.Info($"提升机报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
        //            }
        //        }
        //        else
        //        {
        //            //如果原来有 现在没有 则删除
        //            if (errorList.Where(x => x.ErrorName == errorMessage.ENAlarmMessage).Count() != 0)
        //            {
        //                //删除错误
        //                string delGuid = errorService.DeleteliftError(errorMessage.ENAlarmMessage);
        //                Guid.TryParse(delGuid, out Guid guidRes);
        //                CFXOven.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
        //                if (_appConfig.IsAlarmLog)
        //                    _log.Info($"提升机报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
        //            }
        //        }
        //    }
        //}


        ///// <summary>
        ///// 报警点位刷新（旧）
        ///// </summary>
        //public void TimerCallback_Old(object? state)
        //{
        //    try
        //    {
        //        byte[] errorBytes1 = new byte[1];
        //        //隧道烤箱报警
        //        var result20 = _plc.ReadBytes(_plc.DeltaInstance0, "D100", 1);
        //        //真空箱1报警
        //        var result21 = _plc.ReadBytes(_plc.DeltaInstance1, "D80", 11);
        //        //真空箱2报警
        //        var result22 = _plc.ReadBytes(_plc.DeltaInstance2, "D80", 11);
        //        //提升机报警
        //        var result23 = _plc.ReadBytes(_plc.DeltaInstance3, "D100", 1);
        //        if (result20.IsSuccess && result20.Content != null)
        //        {
        //            BitArray bits20 = new BitArray(ToolBusiness.SwapAdjacentBytes(result20.Content));
        //            bool[] bools20 = new bool[bits20.Count];
        //            bits20.CopyTo(bools20, 0);
        //            OvenAlarmAnalyse(bools20);
        //        }
        //        if (result21.IsSuccess && result21.Content != null)
        //        {
        //            BitArray bits21 = new BitArray(ToolBusiness.SwapAdjacentBytes(result21.Content));
        //            bool[] bools21 = new bool[bits21.Count];
        //            bits21.CopyTo(bools21, 0);
        //            VacuumAlarm1Analyse(bools21);
        //        }
        //        if (result22.IsSuccess && result22.Content != null)
        //        {
        //            BitArray bits22 = new BitArray(ToolBusiness.SwapAdjacentBytes(result22.Content));
        //            bool[] bools22 = new bool[bits22.Count];
        //            bits22.CopyTo(bools22, 0);
        //            VacuumAlarm2Analyse(bools22);
        //        }
        //        if (result23.IsSuccess && result23.Content != null)
        //        {
        //            BitArray bits23 = new BitArray(ToolBusiness.SwapAdjacentBytes(result23.Content));
        //            bool[] bools23 = new bool[bits23.Count];
        //            bits23.CopyTo(bools23, 0);
        //            LiftAlarmAnalyse(bools23);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        _log.Error("报警信息处理发生错误", ex);
        //    }
        //}
    }
}
