|
|
@ -1,7 +1,9 @@
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
using Common.Const;
|
|
|
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
using HybirdFrameworkCore.Const;
|
|
|
|
using HybirdFrameworkCore.Const;
|
|
|
|
using HybirdFrameworkDriver.ModbusTcpMaster;
|
|
|
|
using HybirdFrameworkDriver.ModbusTcpMaster;
|
|
|
|
|
|
|
|
using log4net;
|
|
|
|
using Repository.Station;
|
|
|
|
using Repository.Station;
|
|
|
|
using Service.Plc.Msg;
|
|
|
|
using Service.Plc.Msg;
|
|
|
|
|
|
|
|
|
|
|
@ -13,16 +15,20 @@ namespace Service.Plc.Client;
|
|
|
|
[Scope]
|
|
|
|
[Scope]
|
|
|
|
public class PlcClient : ModbusTcpMaster
|
|
|
|
public class PlcClient : ModbusTcpMaster
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private BinInfoRepository _binInfoRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PlcClient(BinInfoRepository binInfoRepository)
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcClient));
|
|
|
|
|
|
|
|
public BinInfoRepository BinInfoRepository { get; set; }
|
|
|
|
|
|
|
|
public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
|
|
|
|
|
|
|
|
public EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; }
|
|
|
|
|
|
|
|
public EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PlcClient()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ReadAction = BatchRead;
|
|
|
|
ReadAction = BatchRead;
|
|
|
|
Ip = "172.0.20.66";
|
|
|
|
Ip = "172.0.20.66";
|
|
|
|
Port = 502;
|
|
|
|
Port = 502;
|
|
|
|
Duration = 1000;
|
|
|
|
Duration = 1000;
|
|
|
|
AutoReConnect = true;
|
|
|
|
AutoReConnect = true;
|
|
|
|
_binInfoRepository = binInfoRepository;
|
|
|
|
|
|
|
|
ByteSeq = EndingConst.ByteSeq.BA;
|
|
|
|
ByteSeq = EndingConst.ByteSeq.BA;
|
|
|
|
WordSeq= EndingConst.WordSeq.CD;
|
|
|
|
WordSeq= EndingConst.WordSeq.CD;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -60,16 +66,73 @@ public class PlcClient : ModbusTcpMaster
|
|
|
|
var bytes03 = master.BatchReadHolderRegister(701, 10);
|
|
|
|
var bytes03 = master.BatchReadHolderRegister(701, 10);
|
|
|
|
if (bytes03 != null)
|
|
|
|
if (bytes03 != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
|
|
|
|
PlcMgr.DataValidityTime = DateTime.Now;
|
|
|
|
PlcMgr.DataValidityTime = DateTime.Now;
|
|
|
|
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
|
|
|
|
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
|
|
|
|
EndingConst.WordSeq.DC);
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void SaveAlarmInfo(int lastErrorCode, int errorCode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (lastErrorCode == errorCode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateBinInfo(int exists, string binNo)
|
|
|
|
private void UpdateBinInfo(int exists, string binNo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (exists == 0)
|
|
|
|
if (exists == 0)
|
|
|
|
_binInfoRepository.Update(
|
|
|
|
BinInfoRepository.Update(
|
|
|
|
it =>
|
|
|
|
it =>
|
|
|
|
new BinInfo(){
|
|
|
|
new BinInfo(){
|
|
|
|
Exists = 0,
|
|
|
|
Exists = 0,
|
|
|
@ -81,7 +144,7 @@ public class PlcClient : ModbusTcpMaster
|
|
|
|
it => it.No == binNo);
|
|
|
|
it => it.No == binNo);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
|
|
_binInfoRepository.Update(it => it.Exists == 1,
|
|
|
|
BinInfoRepository.Update(it => it.Exists == 1,
|
|
|
|
it => it.No == binNo);
|
|
|
|
it => it.No == binNo);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|