|
|
|
@ -63,29 +63,40 @@ public class PlcClient : ModbusTcpMaster
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bytes03 = master.BatchReadHolderRegister(701, 10);
|
|
|
|
|
var bytes03 = master.BatchReadHolderRegister(701, 32);
|
|
|
|
|
if (bytes03 != null)
|
|
|
|
|
{
|
|
|
|
|
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
|
|
|
|
|
PlcMgr.DataValidityTime = DateTime.Now;
|
|
|
|
|
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
|
|
|
|
|
EndingConst.WordSeq.DC);
|
|
|
|
|
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode01.Value, PlcMgr.PlcFaultData.ErrorCode01.Value);
|
|
|
|
|
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode03.Value, PlcMgr.PlcFaultData.ErrorCode03.Value);
|
|
|
|
|
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode05.Value, PlcMgr.PlcFaultData.ErrorCode05.Value);
|
|
|
|
|
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode07.Value, PlcMgr.PlcFaultData.ErrorCode07.Value);
|
|
|
|
|
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode09.Value, PlcMgr.PlcFaultData.ErrorCode09.Value);
|
|
|
|
|
EndingConst.WordSeq.CD);
|
|
|
|
|
List<string> alarm = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode01.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode02.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode03.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode04.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode05.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode06.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode07.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode08.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode09.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode10.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode11.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode12.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode13.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode14.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode15.Value.ToString(),
|
|
|
|
|
PlcMgr.PlcFaultData.ErrorCode16.Value.ToString(),
|
|
|
|
|
};
|
|
|
|
|
SaveAlarmInfo(alarm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveAlarmInfo(int lastErrorCode, int errorCode)
|
|
|
|
|
private void SaveAlarmInfo(List<string> lstAlarm)
|
|
|
|
|
{
|
|
|
|
|
if (lastErrorCode == errorCode)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string plc = "plc";
|
|
|
|
|
if (errorCode != 0)
|
|
|
|
|
/*if (errorCode != 0)
|
|
|
|
|
{
|
|
|
|
|
EquipAlarmDefine? alarmDefine = EquipAlarmDefineRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode.ToString());
|
|
|
|
|
if (alarmDefine == null)
|
|
|
|
@ -104,8 +115,6 @@ public class PlcClient : ModbusTcpMaster
|
|
|
|
|
ProcessMethod = alarmDefine.ProcessMethod
|
|
|
|
|
};
|
|
|
|
|
EquipAlarmRecordRepository.Insert(record);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -125,8 +134,96 @@ public class PlcClient : ModbusTcpMaster
|
|
|
|
|
EquipAlarmProcessRecordRepository.Insert(processRecord);
|
|
|
|
|
EquipAlarmRecordRepository.DeleteById(alarmRecord.Id);
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
if (lstAlarm.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
#region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录
|
|
|
|
|
|
|
|
|
|
var lstEquipAlarmRecord=EquipAlarmRecordRepository.Query();
|
|
|
|
|
var sqllstAlarm=lstEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList();
|
|
|
|
|
|
|
|
|
|
// 找出实时报警中存在但数据库中不存在的元素
|
|
|
|
|
List<string> uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList();
|
|
|
|
|
|
|
|
|
|
// 找出数据库中存在但实时报警中不存在的元素
|
|
|
|
|
List<string> uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList();
|
|
|
|
|
|
|
|
|
|
if (uniqueToList1.Count > 0)
|
|
|
|
|
{//这里要添加新的报警数据
|
|
|
|
|
foreach (var errorCode in uniqueToList1)
|
|
|
|
|
{
|
|
|
|
|
EquipAlarmDefine? alarmDefine = EquipAlarmDefineRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode);
|
|
|
|
|
if (alarmDefine != null)
|
|
|
|
|
{
|
|
|
|
|
EquipAlarmRecord record = new EquipAlarmRecord()
|
|
|
|
|
{
|
|
|
|
|
EquipTypeCode = alarmDefine.EquipTypeCode,
|
|
|
|
|
EquipCode = alarmDefine.EquipCode,
|
|
|
|
|
ErrorCode = alarmDefine.ErrorCode,
|
|
|
|
|
ErrorLevel = alarmDefine.ErrorLevel,
|
|
|
|
|
ErrorMsg = alarmDefine.ErrorMsg,
|
|
|
|
|
ProcessMethod = alarmDefine.ProcessMethod,
|
|
|
|
|
StartTime= DateTime.Now
|
|
|
|
|
};
|
|
|
|
|
EquipAlarmRecordRepository.Insert(record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uniqueToList2.Count > 0)
|
|
|
|
|
{//这些是要清除实时报警,并且处理记录的。
|
|
|
|
|
// 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象
|
|
|
|
|
List<EquipAlarmRecord> filteredObjectList = lstEquipAlarmRecord
|
|
|
|
|
.Where(obj => uniqueToList2.Contains(obj.ErrorCode))
|
|
|
|
|
.ToList();
|
|
|
|
|
foreach (var VARIABLE in filteredObjectList)
|
|
|
|
|
{
|
|
|
|
|
EquipAlarmProcessRecord EquipAlarmProcessRecord = new EquipAlarmProcessRecord();
|
|
|
|
|
EquipAlarmProcessRecord.EquipTypeCode = VARIABLE.EquipTypeCode;
|
|
|
|
|
EquipAlarmProcessRecord.EquipCode = VARIABLE.EquipCode;
|
|
|
|
|
EquipAlarmProcessRecord.ErrorCode = VARIABLE.ErrorCode;
|
|
|
|
|
EquipAlarmProcessRecord.ErrorLevel = VARIABLE.ErrorLevel;
|
|
|
|
|
EquipAlarmProcessRecord.ErrorMsg = VARIABLE.ErrorMsg;
|
|
|
|
|
EquipAlarmProcessRecord.ProcessMethod = VARIABLE.ProcessMethod;
|
|
|
|
|
EquipAlarmProcessRecord.StartTime = VARIABLE.StartTime;
|
|
|
|
|
EquipAlarmProcessRecord.ProcessTime=DateTime.Now;
|
|
|
|
|
|
|
|
|
|
EquipAlarmProcessRecordRepository.Insert(EquipAlarmProcessRecord);
|
|
|
|
|
}
|
|
|
|
|
EquipAlarmRecordRepository.Delete(filteredObjectList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#region 没报警把已处理记录更新并删除实时报警
|
|
|
|
|
|
|
|
|
|
var lstEquipAlarmRecord=EquipAlarmRecordRepository.Query();
|
|
|
|
|
if (lstEquipAlarmRecord.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var VARIABLE in lstEquipAlarmRecord)
|
|
|
|
|
{
|
|
|
|
|
EquipAlarmProcessRecord EquipAlarmProcessRecord = new EquipAlarmProcessRecord();
|
|
|
|
|
EquipAlarmProcessRecord.EquipTypeCode = VARIABLE.EquipTypeCode;
|
|
|
|
|
EquipAlarmProcessRecord.EquipCode = VARIABLE.EquipCode;
|
|
|
|
|
EquipAlarmProcessRecord.ErrorCode = VARIABLE.ErrorCode;
|
|
|
|
|
EquipAlarmProcessRecord.ErrorLevel = VARIABLE.ErrorLevel;
|
|
|
|
|
EquipAlarmProcessRecord.ErrorMsg = VARIABLE.ErrorMsg;
|
|
|
|
|
EquipAlarmProcessRecord.ProcessMethod = VARIABLE.ProcessMethod;
|
|
|
|
|
EquipAlarmProcessRecord.StartTime = VARIABLE.StartTime;
|
|
|
|
|
EquipAlarmProcessRecord.ProcessTime=DateTime.Now;
|
|
|
|
|
|
|
|
|
|
EquipAlarmProcessRecordRepository.Insert(EquipAlarmProcessRecord);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EquipAlarmRecordRepository.Delete(i=>i.Id>0);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBinInfo(int exists, string binNo)
|
|
|
|
|