From 3bb74c71f506ac322250aed03e8228f14ac706b4 Mon Sep 17 00:00:00 2001 From: zby <24947@USER> Date: Sun, 22 Sep 2024 23:56:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9plc=E6=8A=A5=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Plc/Client/ClientMgr.cs | 2 + Service/Plc/Client/PlcClient.cs | 11 +- Service/Plc/Client/PlcConst.cs | 3 +- .../Plc/Handler/SummaryFailuresReqHandler.cs | 427 +++++++++--------- 4 files changed, 230 insertions(+), 213 deletions(-) diff --git a/Service/Plc/Client/ClientMgr.cs b/Service/Plc/Client/ClientMgr.cs index d1ae38b..377593e 100644 --- a/Service/Plc/Client/ClientMgr.cs +++ b/Service/Plc/Client/ClientMgr.cs @@ -60,6 +60,8 @@ public static class ClientMgr PlcClient.Connect(); PlcClient.SessionAttr(netInfo.Code, netInfo.DestAddr); + + PlcConst.EquipAlarmDefines = PlcClient.GetAlarmDeinneList(); Log.Info($"succeed to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); } catch (Exception ex) diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs index 3b3a665..9ef0621 100644 --- a/Service/Plc/Client/PlcClient.cs +++ b/Service/Plc/Client/PlcClient.cs @@ -1,8 +1,12 @@ -using HybirdFrameworkCore.Autofac.Attribute; +using Autofac; +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac; +using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; using HybirdFrameworkDriver.Session; using HybirdFrameworkDriver.TcpClient; using log4net; +using Repository.Station; using Service.Charger.Client; using Service.Charger.Codec; using Service.Charger.Handler; @@ -314,7 +318,12 @@ public class PlcClient : TcpClient return Result.Success(); } + public EquipAlarmDefineRepository _equipAlarmDefineRepository = AppInfo.Container.Resolve(); + public List GetAlarmDeinneList() + { + return _equipAlarmDefineRepository.QueryByClauseToList(i => i.EquipCode == "plc"); + } /// diff --git a/Service/Plc/Client/PlcConst.cs b/Service/Plc/Client/PlcConst.cs index 7179bf8..c1b6e1d 100644 --- a/Service/Plc/Client/PlcConst.cs +++ b/Service/Plc/Client/PlcConst.cs @@ -1,4 +1,5 @@ using DotNetty.Common.Utilities; +using Entity.DbModel.Station; namespace Service.Charger.Client; @@ -13,7 +14,7 @@ public class PlcConst public static readonly AttributeKey EqmCode = AttributeKey.ValueOf("eqm_code"); public static readonly AttributeKey DestAddr = AttributeKey.ValueOf("dest_addr"); - + public static List EquipAlarmDefines = new List(); } \ No newline at end of file diff --git a/Service/Plc/Handler/SummaryFailuresReqHandler.cs b/Service/Plc/Handler/SummaryFailuresReqHandler.cs index c45276d..adcf172 100644 --- a/Service/Plc/Handler/SummaryFailuresReqHandler.cs +++ b/Service/Plc/Handler/SummaryFailuresReqHandler.cs @@ -11,6 +11,7 @@ using Repository.Station; using Service.Charger.Client; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Charger.Resp; +using SixLabors.ImageSharp; namespace Service.Charger.Handler; @@ -40,25 +41,29 @@ public class SummaryFailuresReqHandler : SimpleChannelInboundHandler private static readonly ILog Log = LogManager.GetLogger(typeof(SummaryFailuresReqHandler)); - List lstEquipAlarmDefine = new List(); - + void Alarm(string number) { - EquipAlarmDefine alarm = lstEquipAlarmDefine.Where(i => i.ErrorCode == number).First(); - if (alarm != null) + if (PlcConst.EquipAlarmDefines.Count>0) { - EquipAlarmRecordRepository.Insert(new EquipAlarmRecord() + EquipAlarmDefine alarm = PlcConst.EquipAlarmDefines.Where(i => i.ErrorCode == number).First(); + + if (alarm != null) { - EquipTypeCode = alarm.EquipTypeCode, - EquipCode = alarm.EquipCode, - ErrorCode = alarm.ErrorCode, - ErrorLevel = alarm.ErrorLevel, - ErrorMsg = alarm.ErrorMsg, - ProcessMethod = alarm.ProcessMethod, - StartTime = DateTime.Now, - }); + EquipAlarmRecordRepository.Insert(new EquipAlarmRecord() + { + EquipTypeCode = alarm.EquipTypeCode, + EquipCode = alarm.EquipCode, + ErrorCode = alarm.ErrorCode, + ErrorLevel = alarm.ErrorLevel, + ErrorMsg = alarm.ErrorMsg, + ProcessMethod = alarm.ProcessMethod, + StartTime = DateTime.Now, + }); + } } + } /// @@ -74,211 +79,211 @@ public class SummaryFailuresReqHandler : SimpleChannelInboundHandler i.EquipCode == "plc"); - //List lstAlarm = new List(); - //if (msg.ScreenEmergencyStop) - // Alarm("1"); - //if (msg.PassageEmergencyStop) - // Alarm("2"); - //if (msg.RobotEmergencyStop) - // Alarm("3"); - //if (msg.FaultyRelays) - // Alarm("4"); - //if (msg.TelecommFailures) - // Alarm("5"); - //if (msg.MasterFailures) - // Alarm("6"); - //if (msg.TitleFailures) - // Alarm("7"); - //if (msg.TitleXFailures) - // Alarm("8"); - //if (msg.TitleYFailures) - // Alarm("9"); - //if (msg.TitleZFailures) - // Alarm("10"); - //if (msg.TitleMFailures) - // Alarm("11"); - //if (msg.WireBroken0) - // Alarm("12"); - //if (msg.WireBroken1) - // Alarm("13"); - //if (msg.WireBroken2) - // Alarm("14"); - //if (msg.WireBroken3) - // Alarm("15"); - //if (msg.XPositiveLimit) - // Alarm("16"); - //if (msg.XNegativeLimit) - // Alarm("17"); - //if (msg.YPositiveLimit) - // Alarm("18"); - //if (msg.YNegativeLimit) - // Alarm("19"); - //if (msg.ZPositiveLimit) - // Alarm("20"); - //if (msg.ZNegativeLimit) - // Alarm("21"); - //if (msg.MPositiveLimit) - // Alarm("22"); - //if (msg.MNegativeLimit) - // Alarm("23"); - //if (msg.XDriveFailure) - // Alarm("24"); - //if (msg.YDriveFailure) - // Alarm("25"); - //if (msg.ZDriveFailure) - // Alarm("26"); - //if (msg.MDriveFailure) - // Alarm("27"); - //if (msg.DoorLeft) - // Alarm("28"); - //if (msg.DoorcloseLeft) - // Alarm("29"); - //if (msg.DoorRight) - // Alarm("30"); - //if (msg.DoorcloseRight) - // Alarm("31"); - //if (msg.DoorRepaiDhambers) - // Alarm("32"); - //if (msg.DoorcloseRepairChambers) - // Alarm("33"); - //if (msg.DoorRepaiCabinet) - // Alarm("34"); - //if (msg.DoorRowFrames) - // Alarm("35"); - //if (msg.X1RetractionFailure) - // Alarm("36"); - //if (msg.X1StickingFault) - // Alarm("37"); - //if (msg.X2RetractionFailure) - // Alarm("38"); - //if (msg.X2StickingFault) - // Alarm("39"); - //if (msg.LocalBattIncorrect) - // Alarm("40"); - //if (msg.NoLocalBattery) - // Alarm("41"); - //if (msg.LocalStorageBatteries) - // Alarm("42"); - //if (msg.RemoteBattIncorrect) - // Alarm("43"); - //if (msg.RemoteBattery) - // Alarm("44"); - //if (msg.RemoteStorageBatteries) - // Alarm("45"); - //if (msg.RemoteMoveLibraryBattery) - // Alarm("46"); - //if (msg.RemoteLibraryBatteries) - // Alarm("47"); - //if (msg.RemoteAreBatteries) - // Alarm("48"); - //if (msg.RemoteMoveElectLibrary) - // Alarm("49"); - //if (msg.RemoteelectrLibrary) - // Alarm("50"); - //if (msg.RemoteelectrAreBatteries) - // Alarm("51"); - //if (msg.RemoteStorageLibrary) - // Alarm("52"); - //if (msg.RemotStorageAreBatteries) - // Alarm("53"); - //if (msg.RemoteOutboundLibrary) - // Alarm("54"); - //if (msg.RemotOutboundAreBatteries) - // Alarm("55"); - //if (msg.RemoteBackupLibrary) - // Alarm("56"); - //if (msg.RemotBackupAreBatteries) - // Alarm("57"); - //if (msg.BatteryCompartAbnormal01) - // Alarm("58"); - //if (msg.BatteryCompartAbnormal02) - // Alarm("59"); - //if (msg.BatteryCompartAbnormal03) - // Alarm("60"); - //if (msg.BatteryCompartAbnormal04) - // Alarm("61"); - //if (msg.BatteryCompartAbnormal05) - // Alarm("62"); - //if (msg.BatteryCompartAbnormal06) - // Alarm("63"); - //if (msg.BatteryCompartAbnormal07) - // Alarm("64"); - //if (msg.BatteryCompartAbnormal08) - // Alarm("65"); - //if (msg.BatteryCompartAbnormal09) - // Alarm("66"); - //if (msg.BatteryWasDetectCompartment) - // Alarm("67"); - //if (msg.RepairWasDetectCompartment) - // Alarm("68"); - //if (msg.WasDetectCompartment214) - // Alarm("69"); - //if (msg.ZSpreaderForceSensor) - // Alarm("70"); - //if (msg.YZSafetyBitAlarm) - // Alarm("71"); - //if (msg.YZSafetyWarehouseBitAlarm) - // Alarm("72"); + List lstAlarm = new List(); + if (msg.ScreenEmergencyStop) + Alarm("1"); + if (msg.PassageEmergencyStop) + Alarm("2"); + if (msg.RobotEmergencyStop) + Alarm("3"); + if (msg.FaultyRelays) + Alarm("4"); + if (msg.TelecommFailures) + Alarm("5"); + if (msg.MasterFailures) + Alarm("6"); + if (msg.TitleFailures) + Alarm("7"); + if (msg.TitleXFailures) + Alarm("8"); + if (msg.TitleYFailures) + Alarm("9"); + if (msg.TitleZFailures) + Alarm("10"); + if (msg.TitleMFailures) + Alarm("11"); + if (msg.WireBroken0) + Alarm("12"); + if (msg.WireBroken1) + Alarm("13"); + if (msg.WireBroken2) + Alarm("14"); + if (msg.WireBroken3) + Alarm("15"); + if (msg.XPositiveLimit) + Alarm("16"); + if (msg.XNegativeLimit) + Alarm("17"); + if (msg.YPositiveLimit) + Alarm("18"); + if (msg.YNegativeLimit) + Alarm("19"); + if (msg.ZPositiveLimit) + Alarm("20"); + if (msg.ZNegativeLimit) + Alarm("21"); + if (msg.MPositiveLimit) + Alarm("22"); + if (msg.MNegativeLimit) + Alarm("23"); + if (msg.XDriveFailure) + Alarm("24"); + if (msg.YDriveFailure) + Alarm("25"); + if (msg.ZDriveFailure) + Alarm("26"); + if (msg.MDriveFailure) + Alarm("27"); + if (msg.DoorLeft) + Alarm("28"); + if (msg.DoorcloseLeft) + Alarm("29"); + if (msg.DoorRight) + Alarm("30"); + if (msg.DoorcloseRight) + Alarm("31"); + if (msg.DoorRepaiDhambers) + Alarm("32"); + if (msg.DoorcloseRepairChambers) + Alarm("33"); + if (msg.DoorRepaiCabinet) + Alarm("34"); + if (msg.DoorRowFrames) + Alarm("35"); + if (msg.X1RetractionFailure) + Alarm("36"); + if (msg.X1StickingFault) + Alarm("37"); + if (msg.X2RetractionFailure) + Alarm("38"); + if (msg.X2StickingFault) + Alarm("39"); + if (msg.LocalBattIncorrect) + Alarm("40"); + if (msg.NoLocalBattery) + Alarm("41"); + if (msg.LocalStorageBatteries) + Alarm("42"); + if (msg.RemoteBattIncorrect) + Alarm("43"); + if (msg.RemoteBattery) + Alarm("44"); + if (msg.RemoteStorageBatteries) + Alarm("45"); + if (msg.RemoteMoveLibraryBattery) + Alarm("46"); + if (msg.RemoteLibraryBatteries) + Alarm("47"); + if (msg.RemoteAreBatteries) + Alarm("48"); + if (msg.RemoteMoveElectLibrary) + Alarm("49"); + if (msg.RemoteelectrLibrary) + Alarm("50"); + if (msg.RemoteelectrAreBatteries) + Alarm("51"); + if (msg.RemoteStorageLibrary) + Alarm("52"); + if (msg.RemotStorageAreBatteries) + Alarm("53"); + if (msg.RemoteOutboundLibrary) + Alarm("54"); + if (msg.RemotOutboundAreBatteries) + Alarm("55"); + if (msg.RemoteBackupLibrary) + Alarm("56"); + if (msg.RemotBackupAreBatteries) + Alarm("57"); + if (msg.BatteryCompartAbnormal01) + Alarm("58"); + if (msg.BatteryCompartAbnormal02) + Alarm("59"); + if (msg.BatteryCompartAbnormal03) + Alarm("60"); + if (msg.BatteryCompartAbnormal04) + Alarm("61"); + if (msg.BatteryCompartAbnormal05) + Alarm("62"); + if (msg.BatteryCompartAbnormal06) + Alarm("63"); + if (msg.BatteryCompartAbnormal07) + Alarm("64"); + if (msg.BatteryCompartAbnormal08) + Alarm("65"); + if (msg.BatteryCompartAbnormal09) + Alarm("66"); + if (msg.BatteryWasDetectCompartment) + Alarm("67"); + if (msg.RepairWasDetectCompartment) + Alarm("68"); + if (msg.WasDetectCompartment214) + Alarm("69"); + if (msg.ZSpreaderForceSensor) + Alarm("70"); + if (msg.YZSafetyBitAlarm) + Alarm("71"); + if (msg.YZSafetyWarehouseBitAlarm) + Alarm("72"); - ////查询当前PLC的实时报警信息 - //var lstNowEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipCode == "plc"); - //var sqllstAlarm = lstNowEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList(); //当前报警列表 - //// 找出实时报警中存在但数据库中不存在的元素 - //List uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList(); + //查询当前PLC的实时报警信息 + var lstNowEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipCode == "plc"); + var sqllstAlarm = lstNowEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList(); //当前报警列表 - //// 找出数据库中存在但实时报警中不存在的元素 - //List uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList(); - //if (uniqueToList1.Count > 0) - //{ - // //这里要添加新的报警数据 - // foreach (var errorCode in uniqueToList1) - // { - // EquipAlarmDefine? alarmDefine = - // EquipAlarmDefineRepository.QueryByClause(i => i.ErrorCode == errorCode); - // if (alarmDefine != null) - // { - // EquipAlarmRecord record = new EquipAlarmRecord() - // { - // EquipTypeCode = alarmDefine.EquipTypeCode, - // EquipCode = "plc", - // ErrorCode = errorCode, - // ErrorLevel = alarmDefine.ErrorLevel, - // ErrorMsg = alarmDefine.ErrorMsg, - // ProcessMethod = alarmDefine.ProcessMethod, - // StartTime = DateTime.Now - // }; - // EquipAlarmRecordRepository.Insert(record); - // } - // } - //} - //else if (uniqueToList2.Count > 0) - //{ - // //这些是要清除实时报警,并且处理记录的。 - // // 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象 - // List filteredObjectList = lstNowEquipAlarmRecord - // .Where(obj => uniqueToList2.Contains(obj.ErrorCode)) - // .ToList(); - // foreach (var VARIABLE in filteredObjectList) - // { - // EquipAlarmProcessRecord EquipAlarmProcessRecord = new EquipAlarmProcessRecord(); - // EquipAlarmProcessRecord.EquipTypeCode = VARIABLE.EquipTypeCode; - // EquipAlarmProcessRecord.EquipCode = VARIABLE.EquipCode; - // EquipAlarmProcessRecord.ErrorCode = VARIABLE.ErrorCode; - // EquipAlarmProcessRecord.ErrorLevel = VARIABLE.ErrorLevel; - // EquipAlarmProcessRecord.ErrorMsg = VARIABLE.ErrorMsg; - // EquipAlarmProcessRecord.ProcessMethod = VARIABLE.ProcessMethod; - // EquipAlarmProcessRecord.StartTime = VARIABLE.StartTime; - // EquipAlarmProcessRecord.ProcessTime = DateTime.Now; + // 找出实时报警中存在但数据库中不存在的元素 + List uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList(); - // EquipAlarmProcessRecordRepository.Insert(EquipAlarmProcessRecord); - // } + // 找出数据库中存在但实时报警中不存在的元素 + List uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList(); + if (uniqueToList1.Count > 0) + { + //这里要添加新的报警数据 + foreach (var errorCode in uniqueToList1) + { + EquipAlarmDefine? alarmDefine = + EquipAlarmDefineRepository.QueryByClause(i => i.ErrorCode == errorCode); + if (alarmDefine != null) + { + EquipAlarmRecord record = new EquipAlarmRecord() + { + EquipTypeCode = alarmDefine.EquipTypeCode, + EquipCode = "plc", + ErrorCode = errorCode, + ErrorLevel = alarmDefine.ErrorLevel, + ErrorMsg = alarmDefine.ErrorMsg, + ProcessMethod = alarmDefine.ProcessMethod, + StartTime = DateTime.Now + }; + EquipAlarmRecordRepository.Insert(record); + } + } + } + else if (uniqueToList2.Count > 0) + { + //这些是要清除实时报警,并且处理记录的。 + // 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象 + List filteredObjectList = lstNowEquipAlarmRecord + .Where(obj => uniqueToList2.Contains(obj.ErrorCode)) + .ToList(); + foreach (var VARIABLE in filteredObjectList) + { + EquipAlarmProcessRecord EquipAlarmProcessRecord = new EquipAlarmProcessRecord(); + EquipAlarmProcessRecord.EquipTypeCode = VARIABLE.EquipTypeCode; + EquipAlarmProcessRecord.EquipCode = VARIABLE.EquipCode; + EquipAlarmProcessRecord.ErrorCode = VARIABLE.ErrorCode; + EquipAlarmProcessRecord.ErrorLevel = VARIABLE.ErrorLevel; + EquipAlarmProcessRecord.ErrorMsg = VARIABLE.ErrorMsg; + EquipAlarmProcessRecord.ProcessMethod = VARIABLE.ProcessMethod; + EquipAlarmProcessRecord.StartTime = VARIABLE.StartTime; + EquipAlarmProcessRecord.ProcessTime = DateTime.Now; - // EquipAlarmRecordRepository.Delete(filteredObjectList); - //} + EquipAlarmProcessRecordRepository.Insert(EquipAlarmProcessRecord); + } + + EquipAlarmRecordRepository.Delete(filteredObjectList); + } ClientMgr.PlcClient.Auto = msg.T3 == 1;