diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Alarm/AlarmHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Alarm/AlarmHelper.cs index 81a09f4..3cdfbe3 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Alarm/AlarmHelper.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Alarm/AlarmHelper.cs @@ -308,7 +308,7 @@ namespace Mesnac.Action.ChemicalWeighing.Alarm { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } - string sqlstr = "select Alarm_PLC, Alarm_Block, MIN(Alarm_Word) as Start, (MAX(Alarm_Word) - MIN(Alarm_Word) + 1) as Length from Pmt_Alarm group by Alarm_PLC, Alarm_Block"; + string sqlstr = "select Alarm_PLC,Alarm_Word,Alarm_Bit, Alarm_Block, MIN(Alarm_Word) as Start, (MAX(Alarm_Word) - MIN(Alarm_Word) + 1) as Length from Pmt_Alarm group by Alarm_PLC, Alarm_Block,Alarm_Word,Alarm_Bit"; DataTable dt = dbHelper.GetDataTableBySql(sqlstr); return dt; } @@ -381,6 +381,8 @@ namespace Mesnac.Action.ChemicalWeighing.Alarm entity.AlarmBlock = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Block", String.Empty); entity.Start = Mesnac.Basic.DataProcessor.RowValue(dr, "Start", 0); entity.Length = Mesnac.Basic.DataProcessor.RowValue(dr, "Length", 0); + entity.AlarmWord = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Word", String.Empty); + entity.AlarmBit = Mesnac.Basic.DataProcessor.RowValue(dr, "Alarm_Bit", String.Empty); return entity; } return null; diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Cache/CacheHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Cache/CacheHelper.cs index fd91c42..d06e66c 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Cache/CacheHelper.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Cache/CacheHelper.cs @@ -56,6 +56,7 @@ namespace Mesnac.Action.ChemicalWeighing.Cache newEntity.AlramPLC = entity.AlarmPLC; newEntity.AlarmBlock = entity.AlarmBlock; newEntity.AlarmAddress = entity.AlarmAddress; + newEntity.AlarmBit = entity.AlarmBit.ToString(); _alarmBlockWordList.Add(newEntity); } } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Alarm/AlarmInfo.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Alarm/AlarmInfo.cs index 9bc9298..7428b75 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Alarm/AlarmInfo.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Alarm/AlarmInfo.cs @@ -17,7 +17,8 @@ namespace Mesnac.Action.ChemicalWeighing.Entity private int _start; private int _length; private Int16[] _data; - + private string _alarmWord; + private string _alarmBit; #endregion #region 属性定义 @@ -48,6 +49,18 @@ namespace Mesnac.Action.ChemicalWeighing.Entity set { _data = value; } } + public string AlarmWord + { + get { return _alarmWord; } + set { _alarmWord = value; } + } + + public string AlarmBit + { + get { return _alarmBit; } + set { _alarmBit = value; } + } + #endregion } } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Alarm/SimpleAlarmInfo.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Alarm/SimpleAlarmInfo.cs index a3e07ba..4edfd73 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Alarm/SimpleAlarmInfo.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Alarm/SimpleAlarmInfo.cs @@ -18,6 +18,7 @@ namespace Mesnac.Action.ChemicalWeighing.Entity private int _alarmAddress; private bool[] _isSaveAlarm = new bool[16] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }; //是否保存过报警记录 private Int16 _alarmData = 0; + private string _alarmBit; #endregion @@ -49,6 +50,12 @@ namespace Mesnac.Action.ChemicalWeighing.Entity set { _alarmData = value; } } + public string AlarmBit + { + get { return _alarmBit; } + set { _alarmBit = value; } + } + #endregion } } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs index 00caa4c..8573197 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs @@ -1,6 +1,10 @@ -using Mesnac.PlcUtils; +using DevExpress.Xpo.DB; +using HslCommunication; +using Mesnac.Codd.Session; +using Mesnac.PlcUtils; using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; @@ -26,84 +30,132 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper { List _alarmInfoList = Cache.CacheHelper.AlarmInfoList; List _alarmBlockWordList = Cache.CacheHelper.BlockWordList; + ICSharpCode.Core.LoggingService.Debug("报警参数-实时刷新自动保存报警..."); + #region 读取PLC的报警数据 原方法 Delete By wenjy 2023-08-07 17:10:07 + //foreach (Entity.AlarmInfo info in _alarmInfoList) + //{ + // Int16[] buff = null; + // if (BasePlcHelper.Instance.PlcRead(info.AlarmPLC, info.AlarmBlock, info.Start, info.Length, out buff)) + // { + // foreach (Entity.SimpleAlarmInfo sai in _alarmBlockWordList) + // { + // if (sai.AlramPLC == info.AlarmPLC && sai.AlarmBlock == info.AlarmBlock) //匹配数据块 + // { + // sai.AlarmData = buff[sai.AlarmAddress - info.Start]; //对起始字偏移,为当前字的报警值 + // sai.AlarmData = Mesnac.Basic.DataProcessor.Swap(sai.AlarmData); //注意:西门子PLC需要高低位转换 + // } + // } + // } + // else + // { + // ICSharpCode.Core.LoggingService.Warn(String.Format("从PLC读取报警数据失败:PLC={0},Block={1},Start={2},Len={3}", info.AlarmPLC, info.AlarmBlock, info.Start, info.Length)); + // } - ICSharpCode.Core.LoggingService.Debug("报警参数-实时刷新自动保存报警..."); + //} - #region 读取PLC的报警数据 + #endregion - foreach (Entity.AlarmInfo info in _alarmInfoList) - { - Int16[] buff = null; - //if (BasePlcHelper.Instance.PlcRead(info.AlarmPLC, info.AlarmBlock, info.Start, info.Length, out buff)) - //{ - // foreach(Entity.SimpleAlarmInfo sai in _alarmBlockWordList) - // { - // if (sai.AlramPLC == info.AlarmPLC && sai.AlarmBlock == info.AlarmBlock) //匹配数据块 - // { - // sai.AlarmData = buff[sai.AlarmAddress - info.Start]; //对起始字偏移,为当前字的报警值 - // sai.AlarmData = Mesnac.Basic.DataProcessor.Swap(sai.AlarmData); //注意:西门子PLC需要高低位转换 - // } - // } - //} - //else - //{ - // ICSharpCode.Core.LoggingService.Warn(String.Format("从PLC读取报警数据失败:PLC={0},Block={1},Start={2},Len={3}", info.AlarmPLC, info.AlarmBlock, info.Start, info.Length)); - //} - bool result = plcBusiness.readBoolValue("DB3.DBX2.2"); - ICSharpCode.Core.LoggingService.Debug($"DB3.DBX2.2读取结果:{result}"); + #region 保存报警数据 原方法 Delete By wenjy 2023-08-07 18:05:06 - } + //foreach (Entity.SimpleAlarmInfo sai in _alarmBlockWordList) + //{ + // int[] binaryAlarmData = Mesnac.Basic.DataProcessor.ParseBinaryValue(sai.AlarmData, WordLength); + // for (int i = 0; i < WordLength; i++) + // { + // if (sai.IsSaveAlarm[i] == true && binaryAlarmData[i] == 0) + // { + // //更新报警状态 + // Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, i); + // if (alarmInfo != null) + // { + // Alarm.AlarmHelper.UpdateAlarmLogData(alarmInfo.Alarm_ID,DateTime.Now.ToString()); + // //清除显示的报警列表信息 + // if(Global.PublicVar.Instance.AlarmStrList.Exists(x => x == alarmInfo.AlarmName)) + // { + // Global.PublicVar.Instance.AlarmStrList.Remove(alarmInfo.AlarmName); + // Global.PublicVar.Instance.isFlashFlag = true; + // Global.PublicVar.Instance.isFlashFlagExtend = true; + // } + // } + // } + // if (binaryAlarmData[i] == 0) + // { + // sai.IsSaveAlarm[i] = false; + // } + // if (sai.IsSaveAlarm[i] == false && binaryAlarmData[i] == 1) + // { + // sai.IsSaveAlarm[i] = true; + // //数据保存 + // Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, i); + // if (alarmInfo != null) + // { + // Entity.LR_Alarmlog alarmLogData = new Entity.LR_Alarmlog(); + // alarmLogData.Equip_Code = alarmInfo.Equip_Code; + // alarmLogData.Alarm_ID = alarmInfo.Alarm_ID; + // alarmLogData.Alarm_OccurTime = DateTime.Now.ToString(); + // alarmLogData.Alarm_ClearTime = String.Empty; + // alarmLogData.Alarm_Status = 1; + // alarmLogData.Alarm_GUID = Guid.NewGuid().ToString().ToUpper(); + // Alarm.AlarmHelper.InsertAlarmLogData(alarmLogData); + // Global.PublicVar.Instance.AlarmStrList.Add(alarmInfo.AlarmName); + // Global.PublicVar.Instance.isFlashFlag = true; + // Global.PublicVar.Instance.isFlashFlagExtend = true; + // } + // } + // } + //} #endregion - #region 保存报警数据 - - foreach(Entity.SimpleAlarmInfo sai in _alarmBlockWordList) + foreach (Entity.AlarmInfo info in _alarmInfoList) { - int[] binaryAlarmData = Mesnac.Basic.DataProcessor.ParseBinaryValue(sai.AlarmData, WordLength); - for (int i = 0; i < WordLength; i++) + string address = $"DB{info.AlarmBlock}.DBX{info.AlarmWord}.{info.AlarmBit}"; + OperateResult result = plcBusiness.readBoolValue(address); + ICSharpCode.Core.LoggingService.Debug(string.Format("{0}读取{1}", address, result.IsSuccess == true ? $"成功;读取结果:{result.Content}" : "失败")); + if (result.IsSuccess == true) { - if (sai.IsSaveAlarm[i] == true && binaryAlarmData[i] == 0) + if (result.Content) { - //更新报警状态 - Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, i); - if (alarmInfo != null) + foreach (Entity.SimpleAlarmInfo sai in _alarmBlockWordList) { - Alarm.AlarmHelper.UpdateAlarmLogData(alarmInfo.Alarm_ID,DateTime.Now.ToString()); - //清除显示的报警列表信息 - if(Global.PublicVar.Instance.AlarmStrList.Exists(x => x == alarmInfo.AlarmName)) + if (sai.AlramPLC == info.AlarmPLC && sai.AlarmBlock == info.AlarmBlock && sai.AlarmBit == info.AlarmBit) //匹配数据块 { - Global.PublicVar.Instance.AlarmStrList.Remove(alarmInfo.AlarmName); - Global.PublicVar.Instance.isFlashFlag = true; - Global.PublicVar.Instance.isFlashFlagExtend = true; + sai.AlarmData = Convert.ToInt16(result.Content); //对起始字偏移,为当前字的报警值 + + //更新报警状态 + Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, Convert.ToInt32(sai.AlarmBit)); + if (alarmInfo != null) + { + Alarm.AlarmHelper.UpdateAlarmLogData(alarmInfo.Alarm_ID, DateTime.Now.ToString()); + //清除显示的报警列表信息 + if (Global.PublicVar.Instance.AlarmStrList.Exists(x => x == alarmInfo.AlarmName)) + { + Global.PublicVar.Instance.AlarmStrList.Remove(alarmInfo.AlarmName); + Global.PublicVar.Instance.isFlashFlag = true; + Global.PublicVar.Instance.isFlashFlagExtend = true; + } + + //保存报警信息 + Entity.LR_Alarmlog alarmLogData = new Entity.LR_Alarmlog(); + alarmLogData.Equip_Code = alarmInfo.Equip_Code; + alarmLogData.Alarm_ID = alarmInfo.Alarm_ID; + alarmLogData.Alarm_OccurTime = DateTime.Now.ToString(); + alarmLogData.Alarm_ClearTime = String.Empty; + alarmLogData.Alarm_Status = 1; + alarmLogData.Alarm_GUID = Guid.NewGuid().ToString().ToUpper(); + + Alarm.AlarmHelper.InsertAlarmLogData(alarmLogData); //这里保存数据库有问题 + ICSharpCode.Core.LoggingService.Error("这里保存数据库有问题"); + + Global.PublicVar.Instance.AlarmStrList.Add(alarmInfo.AlarmName); + Global.PublicVar.Instance.isFlashFlag = true; + Global.PublicVar.Instance.isFlashFlagExtend = true; + } } } } - if (binaryAlarmData[i] == 0) - { - sai.IsSaveAlarm[i] = false; - } - if (sai.IsSaveAlarm[i] == false && binaryAlarmData[i] == 1) - { - sai.IsSaveAlarm[i] = true; - //数据保存 - Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, i); - if (alarmInfo != null) - { - Entity.LR_Alarmlog alarmLogData = new Entity.LR_Alarmlog(); - alarmLogData.Equip_Code = alarmInfo.Equip_Code; - alarmLogData.Alarm_ID = alarmInfo.Alarm_ID; - alarmLogData.Alarm_OccurTime = DateTime.Now.ToString(); - alarmLogData.Alarm_ClearTime = String.Empty; - alarmLogData.Alarm_Status = 1; - alarmLogData.Alarm_GUID = Guid.NewGuid().ToString().ToUpper(); - Alarm.AlarmHelper.InsertAlarmLogData(alarmLogData); - Global.PublicVar.Instance.AlarmStrList.Add(alarmInfo.AlarmName); - Global.PublicVar.Instance.isFlashFlag = true; - Global.PublicVar.Instance.isFlashFlagExtend = true; - } - } + } } @@ -119,8 +171,6 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper } #endregion - - #endregion } } } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj index bd42b8a..40e356d 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj @@ -110,6 +110,10 @@ False ..\..\..\A3Lib\FastReport\FastReport.VSDesign.dll + + False + Z:\Desktop\日常代码\榄菊项目\程序设计\lj_plc\PlugInPlatform\HslCommunication.dll + False ..\..\..\PlugInPlatform\ICSharpCode.Core.dll diff --git a/Mesnac.PlcUtils/IPlc.cs b/Mesnac.PlcUtils/IPlc.cs index 97d3205..9372a6f 100644 --- a/Mesnac.PlcUtils/IPlc.cs +++ b/Mesnac.PlcUtils/IPlc.cs @@ -1,4 +1,5 @@ -using System; +using HslCommunication; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -100,7 +101,7 @@ namespace Mesnac.PlcUtils /// /// /// - bool readBoolByAddress(string address); + OperateResult readBoolByAddress(string address); /// /// 通过PLC地址写入Bool类型数据 diff --git a/Mesnac.PlcUtils/Impl/OmronNJPlc.cs b/Mesnac.PlcUtils/Impl/OmronNJPlc.cs index 234e2d1..de87a40 100644 --- a/Mesnac.PlcUtils/Impl/OmronNJPlc.cs +++ b/Mesnac.PlcUtils/Impl/OmronNJPlc.cs @@ -359,7 +359,7 @@ namespace Mesnac.PlcUtils.Impl /// /// /// - public bool readBoolByAddress(string address) + public OperateResult readBoolByAddress(string address) { //ICSharpCode.Core.LoggingService.Debug(String.Format("开始通过PLC地址{0}读取bool类型数据", address)); try @@ -368,17 +368,17 @@ namespace Mesnac.PlcUtils.Impl if (read.IsSuccess) { ICSharpCode.Core.LoggingService.Debug(String.Format("通过PLC地址{0}读取bool类型数据成功:{1}", address, read.Content)); - return read.Content; } - ICSharpCode.Core.LoggingService.Debug(String.Format("通过PLC地址{0}读取bool类型数据失败!!!", address)); - this.IsConnected = false; - return false; + else + { + ICSharpCode.Core.LoggingService.Debug(String.Format("通过PLC地址{0}读取bool类型数据失败!!!", address)); + } + return read; } catch (Exception ex) { - ICSharpCode.Core.LoggingService.Error("通过PLC地址读取int32类型数据异常", ex); - this.IsConnected = false; - return false; + ICSharpCode.Core.LoggingService.Error("通过PLC地址读取bool类型数据失败", ex); + return new OperateResult() { IsSuccess = false, Content = false }; } } diff --git a/Mesnac.PlcUtils/Impl/SiemensPlc.cs b/Mesnac.PlcUtils/Impl/SiemensPlc.cs index 4120e52..290a846 100644 --- a/Mesnac.PlcUtils/Impl/SiemensPlc.cs +++ b/Mesnac.PlcUtils/Impl/SiemensPlc.cs @@ -21,11 +21,12 @@ namespace Mesnac.PlcUtils.Impl public SiemensPlc() { - if (!HslCommunication.Authorization.SetAuthorizationCode("30c15272-3960-4853-9fab-3087392ee5cd")) + if (!HslCommunication.Authorization.SetAuthorizationCode("ed1415f8-e06a-43ad-95f7-c04f7ae93b41")) { - ICSharpCode.Core.LoggingService.Error("HslCommunication激活失败"); + ICSharpCode.Core.LoggingService.Error("HslCommunication 11.0.6.0激活失败..."); return; } + ICSharpCode.Core.LoggingService.Debug("HslCommunication 11.0.6.0激活成功"); } public bool IsConnected { get; set; } @@ -348,7 +349,7 @@ namespace Mesnac.PlcUtils.Impl /// /// /// - public bool readBoolByAddress(string address) + public OperateResult readBoolByAddress(string address) { //ICSharpCode.Core.LoggingService.Debug(String.Format("开始通过PLC地址{0}读取bool类型数据", address)); try @@ -357,17 +358,17 @@ namespace Mesnac.PlcUtils.Impl if (read.IsSuccess) { ICSharpCode.Core.LoggingService.Debug(String.Format("通过PLC地址{0}读取bool类型数据成功:{1}", address, read.Content)); - return read.Content; } - ICSharpCode.Core.LoggingService.Debug(String.Format("通过PLC地址{0}读取bool类型数据失败!!!", address)); - this.IsConnected = false; - return false; + else + { + ICSharpCode.Core.LoggingService.Debug(String.Format("通过PLC地址{0}读取bool类型数据失败!!!", address)); + } + return read; } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("通过PLC地址读取int32类型数据异常", ex); - this.IsConnected = false; - return false; + return new OperateResult() { IsSuccess = false, Content = false }; } } diff --git a/Mesnac.PlcUtils/PlcBusiness.cs b/Mesnac.PlcUtils/PlcBusiness.cs index 0dbb021..1b3ac13 100644 --- a/Mesnac.PlcUtils/PlcBusiness.cs +++ b/Mesnac.PlcUtils/PlcBusiness.cs @@ -1,4 +1,5 @@ -using Mesnac.PlcUtils.common; +using HslCommunication; +using Mesnac.PlcUtils.common; using Mesnac.PlcUtils.enumInfo; using Mesnac.PlcUtils.Impl; using System; @@ -69,7 +70,7 @@ namespace Mesnac.PlcUtils } - public bool readBoolValue(string address) + public OperateResult readBoolValue(string address) { if(plcInstance != null) { @@ -77,7 +78,10 @@ namespace Mesnac.PlcUtils } else { - return false; + return new OperateResult() { + IsSuccess = false, + Content = false + }; } }