现场plc故障显示,已测试

zw
CZ 5 months ago
parent ca440d8608
commit 13fcdf4896

@ -67,7 +67,13 @@ namespace Entity.DbModel.Station
/// </summary>
[SugarColumn(ColumnName = "process_method")]
public string ProcessMethod { get; set; }
/// <summary>
/// Desc:开始时间
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "start_time")]
public DateTime? StartTime { get; set; }
/// <summary>
/// Desc:处理时间
/// Default:

@ -68,6 +68,14 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName = "process_method")]
public string ProcessMethod { get; set; }
/// <summary>
/// Desc:开始时间
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "start_time")]
public DateTime? StartTime { get; set; }
}
}

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

@ -5,9 +5,20 @@ namespace Service.Plc.Msg
public class PlcFault
{
public ModbusProperty<int> ErrorCode01 { get; set; } = new(40701,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode03 { get; set; } = new(40703,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode05 { get; set; } = new(40705,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode07 { get; set; } = new(40707,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode09 { get; set; } = new(40709, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode02 { get; set; } = new(40703,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode03 { get; set; } = new(40705,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode04 { get; set; } = new(40707,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode05 { get; set; } = new(40709, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode06 { get; set; } = new(40711, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode07 { get; set; } = new(40713, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode08 { get; set; } = new(40715, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode09 { get; set; } = new(40717, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode10 { get; set; } = new(40719, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode11 { get; set; } = new(40721, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode12 { get; set; } = new(40723, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode13 { get; set; } = new(40725, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode14 { get; set; } = new(40727, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode15 { get; set; } = new(40729, length: 2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode16 { get; set; } = new(40731, length: 2, value: 0); // 错误码
}
}

@ -0,0 +1,4 @@
ALTER TABLE equip_alarm_record
ADD COLUMN start_time DATETIME NULL COMMENT '开始时间';
ALTER TABLE equip_alarm_process_record
ADD COLUMN start_time DATETIME NULL COMMENT '开始时间';
Loading…
Cancel
Save