diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/FinishBatchService.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/FinishBatchService.cs
index f82beb2..3c83a34 100644
--- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/FinishBatchService.cs
+++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/FinishBatchService.cs
@@ -114,7 +114,7 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch
#region 0、实时刷新自动保存报警
- SaveHelper.AlarmSaveHelper.Save();
+ SaveHelper.AlarmSaveHelper.Instance.Save();
#endregion
@@ -157,8 +157,7 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch
#region 7、自动存盘处理
- FinishBatchHelper.SaveGHData();
- //GHFinshBatchHelper.SaveData();
+ //FinishBatchHelper.SaveGHData();
ReportSaveHelper.Instance.SaveDryMixerReport();
#endregion
diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs
index 2702761..ee5cfb0 100644
--- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs
+++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs
@@ -1,6 +1,7 @@
using DevExpress.Xpo.DB;
using FastReport.Export.Dbf;
using HslCommunication;
+using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Codd.Session;
using Mesnac.DoUtils;
using Mesnac.PlcUtils;
@@ -10,6 +11,7 @@ using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
+using static DevExpress.Xpo.Helpers.AssociatedCollectionCriteriaHelper;
namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{
@@ -18,20 +20,32 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
///
/// 报警保存事件定义
///
- public static event EventHandler OnAlarmSave;
- public static event EventHandler OnAlarmSaveExtend;
- public static object sender = null;
- public static object senderExtend = null;
- private static int WordLength = 16; //定义字长
+ public event EventHandler OnAlarmSave;
+ public event EventHandler OnAlarmSaveExtend;
+ public object sender = null;
+ public object senderExtend = null;
+ private int WordLength = 16; //定义字长
- private static PlcBusiness plcBusiness = PlcBusiness.Instance;
+ private PlcBusiness plcBusiness = PlcBusiness.Instance;
- private static DoControl doControl = DoControl.Instance;
+ private DoControl doControl = DoControl.Instance;
+
+ private static readonly Lazy lazy = new Lazy(() => new AlarmSaveHelper());
+
+ public static AlarmSaveHelper Instance
+ {
+ get
+ {
+ return lazy.Value;
+ }
+ }
+
+ private AlarmSaveHelper() { }
///
/// 保存报警信息
///
- public static void Save()
+ public void Save()
{
List _alarmInfoList = Cache.CacheHelper.AlarmInfoList;
List _alarmBlockWordList = Cache.CacheHelper.BlockWordList;
@@ -113,81 +127,130 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
#endregion
- foreach (Entity.AlarmInfo info in _alarmInfoList)
+ try
{
- 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)
+ foreach (Entity.AlarmInfo info in _alarmInfoList)
{
- if (result.Content)
+ 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)
{
- foreach (Entity.SimpleAlarmInfo sai in _alarmBlockWordList)
+ if (result.Content)
{
- if (sai.AlramPLC == info.AlarmPLC && sai.AlarmBlock == info.AlarmBlock && sai.AlarmBit == info.AlarmBit) //匹配数据块
- {
- sai.AlarmData = Convert.ToInt16(result.Content); //对起始字偏移,为当前字的报警值
-
- //打开报警灯:FIRST 关闭绿灯 SECOND 打开红灯
- doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
- doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
-
- //更新报警状态
- 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);
- Global.PublicVar.Instance.AlarmStrList.Add(alarmInfo.AlarmName);
- Global.PublicVar.Instance.isFlashFlag = true;
- Global.PublicVar.Instance.isFlashFlagExtend = true;
- }
- }
+ AlarmLogicalProcessing(_alarmBlockWordList, info);
}
}
- else
- {
- // 关闭报警灯:FIRST 打开红灯 SECOND 关闭绿灯
- doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
- doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
- }
+ AlarmLight(result.Content); //控制报警灯 True红灯;False绿灯
+ }
+ #region 触发事件
+
+ if (OnAlarmSave != null && Global.PublicVar.Instance.isFlashFlag)
+ {
+ OnAlarmSave(sender, System.EventArgs.Empty);
}
- else
+ if (OnAlarmSaveExtend != null && Global.PublicVar.Instance.isFlashFlagExtend)
{
- doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
+ OnAlarmSaveExtend(senderExtend, System.EventArgs.Empty);
}
+
+ #endregion
}
+ catch (Exception ex)
+ {
+ ICSharpCode.Core.LoggingService.Error(String.Format("AlarmSaveHelper逻辑异常:{0}", ex.Message), ex);
+ }
+ }
+
+ ///
+ /// 报警逻辑处理
+ ///
+ ///
+ ///
+ private void AlarmLogicalProcessing(List _alarmBlockWordList, Entity.AlarmInfo info)
+ {
+ if(_alarmBlockWordList != null)
+ {
+ foreach (Entity.SimpleAlarmInfo sai in _alarmBlockWordList)
+ {
+ if (sai.AlramPLC == info.AlarmPLC && sai.AlarmBlock == info.AlarmBlock && sai.AlarmBit == info.AlarmBit) //匹配数据块
+ {
+ sai.AlarmData = 1; //对起始字偏移,为当前字的报警值
- #region 触发事件
+ Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, Convert.ToInt32(sai.AlarmBit));
+ if (alarmInfo != null)
+ {
+ UpdateAlarmLogData(alarmInfo); //更新报警状态
+ InsertAlarmLogData(alarmInfo); //保存报警信息
+ }
+ }
+ }
+ }
+ }
- if (OnAlarmSave != null && Global.PublicVar.Instance.isFlashFlag)
+ ///
+ /// 更新报警状态
+ ///
+ ///
+ private void UpdateAlarmLogData(Entity.PmtAlarmInfo alarmInfo)
+ {
+ if (alarmInfo != null)
{
- OnAlarmSave(sender, System.EventArgs.Empty);
+ 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 (OnAlarmSaveExtend != null && Global.PublicVar.Instance.isFlashFlagExtend)
+ }
+
+ ///
+ /// 保存报警信息
+ ///
+ ///
+ private void InsertAlarmLogData(Entity.PmtAlarmInfo alarmInfo)
+ {
+ if (alarmInfo != null)
{
- OnAlarmSaveExtend(senderExtend, System.EventArgs.Empty);
+ //保存报警信息
+ 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
+ ///
+ /// 报警灯控制
+ ///
+ /// 是否报警
+ private void AlarmLight(bool flag)
+ {
+ if(flag)
+ {
+ //打开报警灯:FIRST 关闭绿灯 SECOND 打开红灯
+ doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
+ doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
+ }
+ else
+ {
+ // 关闭报警灯:FIRST 打开红灯 SECOND 关闭绿灯
+ doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
+ doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
+ }
}
}
}