@ -1,6 +1,10 @@
using Mesnac.PlcUtils ;
using DevExpress.Xpo.DB ;
using HslCommunication ;
using Mesnac.Codd.Session ;
using Mesnac.PlcUtils ;
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Data ;
using System.Linq ;
using System.Linq ;
using System.Text ;
using System.Text ;
@ -26,18 +30,15 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{
{
List < Entity . AlarmInfo > _alarmInfoList = Cache . CacheHelper . AlarmInfoList ;
List < Entity . AlarmInfo > _alarmInfoList = Cache . CacheHelper . AlarmInfoList ;
List < Entity . SimpleAlarmInfo > _alarmBlockWordList = Cache . CacheHelper . BlockWordList ;
List < Entity . SimpleAlarmInfo > _alarmBlockWordList = Cache . CacheHelper . BlockWordList ;
ICSharpCode . Core . LoggingService < AlarmSaveHelper > . Debug ( "报警参数-实时刷新自动保存报警..." ) ;
ICSharpCode . Core . LoggingService < AlarmSaveHelper > . Debug ( "报警参数-实时刷新自动保存报警..." ) ;
#region 读取PLC的报警数据
#region 读取PLC的报警数据 原方法 Delete By wenjy 2023-08-07 17:10:07
//foreach (Entity.AlarmInfo info in _alarmInfoList)
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)
// 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) //匹配数据块
// if (sai.AlramPLC == info.AlarmPLC && sai.AlarmBlock == info.AlarmBlock) //匹配数据块
// {
// {
@ -45,52 +46,97 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
// sai.AlarmData = Mesnac.Basic.DataProcessor.Swap(sai.AlarmData); //注意: 西门子PLC需要高低位转换
// sai.AlarmData = Mesnac.Basic.DataProcessor.Swap(sai.AlarmData); //注意: 西门子PLC需要高低位转换
// }
// }
// }
// }
// }
// }
// else
// else
// {
// {
// ICSharpCode.Core.LoggingService<AlarmSaveHelper>.Warn(String.Format("从PLC读取报警数据失败:PLC={0},Block={1},Start={2},Len={3}", info.AlarmPLC, info.AlarmBlock, info.Start, info.Length));
// ICSharpCode.Core.LoggingService<AlarmSaveHelper>.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 < AlarmSaveHelper > . Debug ( $"DB3.DBX2.2读取结果:{result}" ) ;
}
//}
# endregion
# endregion
#region 保存报警数据
#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
foreach ( Entity . SimpleAlarmInfo sai in _alarmBlockWordList )
foreach ( Entity . AlarmInfo info in _alarmInfoList )
{
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 )
{
if ( result . Content )
{
{
int [ ] binaryAlarmData = Mesnac . Basic . DataProcessor . ParseBinaryValue ( sai . AlarmData , WordLength ) ;
foreach ( Entity . SimpleAlarmInfo sai in _alarmBlockWordList )
for ( int i = 0 ; i < WordLength ; i + + )
{
{
if ( sai . IsSaveAlarm [ i ] = = true & & binaryAlarmData [ i ] = = 0 )
if ( sai . AlramPLC = = info . AlarmPLC & & sai . AlarmBlock = = info . AlarmBlock & & sai . AlarmBit = = info . AlarmBit ) //匹配数据块
{
{
sai . AlarmData = Convert . ToInt16 ( result . Content ) ; //对起始字偏移,为当前字的报警值
//更新报警状态
//更新报警状态
Entity . PmtAlarmInfo alarmInfo = Cache . CacheHelper . GetPmtAlarmInfoFromCache ( sai . AlramPLC , sai . AlarmBlock , sai . AlarmAddress , i ) ;
Entity . PmtAlarmInfo alarmInfo = Cache . CacheHelper . GetPmtAlarmInfoFromCache ( sai . AlramPLC , sai . AlarmBlock , sai . AlarmAddress , Convert. ToInt32 ( sa i. AlarmBit ) ) ;
if ( alarmInfo ! = null )
if ( alarmInfo ! = null )
{
{
Alarm . AlarmHelper . UpdateAlarmLogData ( alarmInfo . Alarm_ID , DateTime . Now . ToString ( ) ) ;
Alarm . AlarmHelper . UpdateAlarmLogData ( alarmInfo . Alarm_ID , DateTime . Now . ToString ( ) ) ;
//清除显示的报警列表信息
//清除显示的报警列表信息
if ( Global . PublicVar . Instance . AlarmStrList . Exists ( x = > x = = alarmInfo . AlarmName ) )
if ( Global . PublicVar . Instance . AlarmStrList . Exists ( x = > x = = alarmInfo . AlarmName ) )
{
{
Global . PublicVar . Instance . AlarmStrList . Remove ( alarmInfo . AlarmName ) ;
Global . PublicVar . Instance . AlarmStrList . Remove ( alarmInfo . AlarmName ) ;
Global . PublicVar . Instance . isFlashFlag = true ;
Global . PublicVar . Instance . isFlashFlag = true ;
Global . PublicVar . Instance . isFlashFlagExtend = 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 ( ) ;
Entity . LR_Alarmlog alarmLogData = new Entity . LR_Alarmlog ( ) ;
alarmLogData . Equip_Code = alarmInfo . Equip_Code ;
alarmLogData . Equip_Code = alarmInfo . Equip_Code ;
alarmLogData . Alarm_ID = alarmInfo . Alarm_ID ;
alarmLogData . Alarm_ID = alarmInfo . Alarm_ID ;
@ -98,7 +144,10 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
alarmLogData . Alarm_ClearTime = String . Empty ;
alarmLogData . Alarm_ClearTime = String . Empty ;
alarmLogData . Alarm_Status = 1 ;
alarmLogData . Alarm_Status = 1 ;
alarmLogData . Alarm_GUID = Guid . NewGuid ( ) . ToString ( ) . ToUpper ( ) ;
alarmLogData . Alarm_GUID = Guid . NewGuid ( ) . ToString ( ) . ToUpper ( ) ;
Alarm . AlarmHelper . InsertAlarmLogData ( alarmLogData ) ;
Alarm . AlarmHelper . InsertAlarmLogData ( alarmLogData ) ; //这里保存数据库有问题
ICSharpCode . Core . LoggingService < AlarmSaveHelper > . Error ( "这里保存数据库有问题" ) ;
Global . PublicVar . Instance . AlarmStrList . Add ( alarmInfo . AlarmName ) ;
Global . PublicVar . Instance . AlarmStrList . Add ( alarmInfo . AlarmName ) ;
Global . PublicVar . Instance . isFlashFlag = true ;
Global . PublicVar . Instance . isFlashFlag = true ;
Global . PublicVar . Instance . isFlashFlagExtend = true ;
Global . PublicVar . Instance . isFlashFlagExtend = true ;
@ -107,6 +156,9 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
}
}
}
}
}
}
#region 触发事件
#region 触发事件
if ( OnAlarmSave ! = null & & Global . PublicVar . Instance . isFlashFlag )
if ( OnAlarmSave ! = null & & Global . PublicVar . Instance . isFlashFlag )
@ -119,8 +171,6 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
}
}
# endregion
# endregion
# endregion
}
}
}
}
}
}