|
|
|
@ -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,6 +127,8 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (Entity.AlarmInfo info in _alarmInfoList)
|
|
|
|
|
{
|
|
|
|
|
string address = $"DB{info.AlarmBlock}.DBX{info.AlarmWord}.{info.AlarmBit}";
|
|
|
|
@ -121,19 +137,64 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
|
|
|
|
|
if (result.IsSuccess == true)
|
|
|
|
|
{
|
|
|
|
|
if (result.Content)
|
|
|
|
|
{
|
|
|
|
|
AlarmLogicalProcessing(_alarmBlockWordList, info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AlarmLight(result.Content); //控制报警灯 True红灯;False绿灯
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 触发事件
|
|
|
|
|
|
|
|
|
|
if (OnAlarmSave != null && Global.PublicVar.Instance.isFlashFlag)
|
|
|
|
|
{
|
|
|
|
|
OnAlarmSave(sender, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
if (OnAlarmSaveExtend != null && Global.PublicVar.Instance.isFlashFlagExtend)
|
|
|
|
|
{
|
|
|
|
|
OnAlarmSaveExtend(senderExtend, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<GHFinshBatchHelper>.Error(String.Format("AlarmSaveHelper逻辑异常:{0}", ex.Message), ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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 = Convert.ToInt16(result.Content); //对起始字偏移,为当前字的报警值
|
|
|
|
|
sai.AlarmData = 1; //对起始字偏移,为当前字的报警值
|
|
|
|
|
|
|
|
|
|
//打开报警灯: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)
|
|
|
|
|
{
|
|
|
|
|
UpdateAlarmLogData(alarmInfo); //更新报警状态
|
|
|
|
|
InsertAlarmLogData(alarmInfo); //保存报警信息
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新报警状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sai"></param>
|
|
|
|
|
private void UpdateAlarmLogData(Entity.PmtAlarmInfo alarmInfo)
|
|
|
|
|
{
|
|
|
|
|
if (alarmInfo != null)
|
|
|
|
|
{
|
|
|
|
|
Alarm.AlarmHelper.UpdateAlarmLogData(alarmInfo.Alarm_ID, DateTime.Now.ToString());
|
|
|
|
@ -144,7 +205,17 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
|
|
|
|
|
Global.PublicVar.Instance.isFlashFlag = true;
|
|
|
|
|
Global.PublicVar.Instance.isFlashFlagExtend = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存报警信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sai"></param>
|
|
|
|
|
private void InsertAlarmLogData(Entity.PmtAlarmInfo alarmInfo)
|
|
|
|
|
{
|
|
|
|
|
if (alarmInfo != null)
|
|
|
|
|
{
|
|
|
|
|
//保存报警信息
|
|
|
|
|
Entity.LR_Alarmlog alarmLogData = new Entity.LR_Alarmlog();
|
|
|
|
|
alarmLogData.Equip_Code = alarmInfo.Equip_Code;
|
|
|
|
@ -159,8 +230,20 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
|
|
|
|
|
Global.PublicVar.Instance.isFlashFlag = true;
|
|
|
|
|
Global.PublicVar.Instance.isFlashFlagExtend = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
|
{
|
|
|
|
@ -168,26 +251,6 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
|
|
|
|
|
doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
|
|
|
|
|
doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 触发事件
|
|
|
|
|
|
|
|
|
|
if (OnAlarmSave != null && Global.PublicVar.Instance.isFlashFlag)
|
|
|
|
|
{
|
|
|
|
|
OnAlarmSave(sender, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
if (OnAlarmSaveExtend != null && Global.PublicVar.Instance.isFlashFlagExtend)
|
|
|
|
|
{
|
|
|
|
|
OnAlarmSaveExtend(senderExtend, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|