删除plc读取多出的else

master
CZ 4 months ago
parent 45e8818eee
commit 8fdfb97b45

@ -121,70 +121,6 @@ public class PlcClient : ModbusTcpMaster
Log.Info("Plc read finish"); Log.Info("Plc read finish");
} }
else if(PlcMgr.PlcClient!=null)
{
Log.Info("Plc use plcClient read");
var bytes01 = PlcMgr.PlcClient.BatchReadHolderRegister(1, 115);
if (bytes01 != null)
{
connectResult = true;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
}
var bytes02 = PlcMgr.PlcClient.BatchReadHolderRegister(201, 222);
if (bytes02 != null)
{
connectResult = true;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
UpdateBinInfoCache(PlcMgr.PlcToHostData.MaterialDetec01.Value, "1");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec02.Value, "2");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec03.Value, "3");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec04.Value, "4");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec05.Value, "5");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec06.Value, "6");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec07.Value, "7");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec08.Value, "8");
}
var bytes03 = PlcMgr.PlcClient.BatchReadHolderRegister(701, 32);
if (bytes03 != null)
{
connectResult = true;
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
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);
}
Log.Info("Plc read finish");
}
} }
catch (Exception e) catch (Exception e)
@ -199,45 +135,6 @@ public class PlcClient : ModbusTcpMaster
private void SaveAlarmInfo(List<string> lstAlarm) private void SaveAlarmInfo(List<string> lstAlarm)
{ {
string plc = "plc"; string plc = "plc";
/*if (errorCode != 0)
{
EquipAlarmDefine? alarmDefine = EquipAlarmDefineRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode.ToString());
if (alarmDefine == null)
{
Log.Error($"error code {errorCode} has no define");
return;
}
EquipAlarmRecord record = new EquipAlarmRecord()
{
EquipTypeCode = alarmDefine.EquipTypeCode,
EquipCode = alarmDefine.EquipCode,
ErrorCode = alarmDefine.ErrorCode,
ErrorLevel = alarmDefine.ErrorLevel,
ErrorMsg = alarmDefine.ErrorMsg,
ProcessMethod = alarmDefine.ProcessMethod
};
EquipAlarmRecordRepository.Insert(record);
}
else
{
EquipAlarmRecord? alarmRecord = EquipAlarmRecordRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode.ToString());
if (alarmRecord != null)
{
EquipAlarmProcessRecord processRecord = new EquipAlarmProcessRecord()
{
EquipTypeCode = alarmRecord.EquipTypeCode,
EquipCode = alarmRecord.EquipCode,
ErrorCode =alarmRecord.EquipCode,
ErrorLevel = alarmRecord.ErrorLevel,
ErrorMsg = alarmRecord.ErrorMsg,
ProcessMethod = alarmRecord.ProcessMethod,
ProcessTime = DateTime.Now
};
EquipAlarmProcessRecordRepository.Insert(processRecord);
EquipAlarmRecordRepository.DeleteById(alarmRecord.Id);
}
}*/
if (lstAlarm.Count > 0) if (lstAlarm.Count > 0)
{ {

Loading…
Cancel
Save