change - 报警读取逻辑代码优化

master
wenjy 1 year ago
parent fcd32f6ee7
commit 1704350b44

@ -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

@ -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
/// <summary>
/// 报警保存事件定义
/// </summary>
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<AlarmSaveHelper> lazy = new Lazy<AlarmSaveHelper>(() => new AlarmSaveHelper());
public static AlarmSaveHelper Instance
{
get
{
return lazy.Value;
}
}
private AlarmSaveHelper() { }
/// <summary>
/// 保存报警信息
/// </summary>
public static void Save()
public void Save()
{
List<Entity.AlarmInfo> _alarmInfoList = Cache.CacheHelper.AlarmInfoList;
List<Entity.SimpleAlarmInfo> _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<bool> result = plcBusiness.readBoolValue(address);
ICSharpCode.Core.LoggingService<AlarmSaveHelper>.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<bool> result = plcBusiness.readBoolValue(address);
ICSharpCode.Core.LoggingService<AlarmSaveHelper>.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<GHFinshBatchHelper>.Error(String.Format("AlarmSaveHelper逻辑异常{0}", ex.Message), ex);
}
}
#region 触发事件
/// <summary>
/// 报警逻辑处理
/// </summary>
/// <param name="_alarmBlockWordList"></param>
/// <param name="info"></param>
private void AlarmLogicalProcessing(List<Entity.SimpleAlarmInfo> _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; //对起始字偏移,为当前字的报警值
if (OnAlarmSave != null && Global.PublicVar.Instance.isFlashFlag)
Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, Convert.ToInt32(sai.AlarmBit));
if (alarmInfo != null)
{
UpdateAlarmLogData(alarmInfo); //更新报警状态
InsertAlarmLogData(alarmInfo); //保存报警信息
}
}
}
}
}
/// <summary>
/// 更新报警状态
/// </summary>
/// <param name="sai"></param>
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)
}
/// <summary>
/// 保存报警信息
/// </summary>
/// <param name="sai"></param>
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
}
/// <summary>
/// 报警灯控制
/// </summary>
/// <param name="flag">是否报警</param>
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);
}
}
}
}

Loading…
Cancel
Save