|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using Common.Const;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using HybirdFrameworkCore.Const;
|
|
|
|
|
using HybirdFrameworkDriver.ModbusTcpMaster;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using Service.FireControl.Msg;
|
|
|
|
|
|
|
|
|
|
namespace Service.FireControl.Client;
|
|
|
|
@ -10,6 +13,9 @@ namespace Service.FireControl.Client;
|
|
|
|
|
public class FireControlClient: ModbusTcpMaster
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(FireControlClient));
|
|
|
|
|
public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
|
|
|
|
|
public EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; }
|
|
|
|
|
public EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; }
|
|
|
|
|
public FireControlClient()
|
|
|
|
|
{
|
|
|
|
|
ReadAction = BatchRead;
|
|
|
|
@ -23,16 +29,40 @@ public class FireControlClient: ModbusTcpMaster
|
|
|
|
|
|
|
|
|
|
private void BatchRead(ModbusTcpMaster master)
|
|
|
|
|
{
|
|
|
|
|
//1电表
|
|
|
|
|
//2消防
|
|
|
|
|
//3温湿度
|
|
|
|
|
Log.Info("fire start read");
|
|
|
|
|
var bytes02 = master.ReadCoil("0x0000", 17).Content;//0x01
|
|
|
|
|
var bytes03 = master.BatchReadHolderRegister(1, 3);//0x03 读1 3
|
|
|
|
|
var bytes04 = master.BatchReadHolderRegister(0x0100, 383);//0x03 读256 383
|
|
|
|
|
var bytes05 = master.BatchReadHolderRegister(1, 115);//0x04 可以
|
|
|
|
|
|
|
|
|
|
#region 电表
|
|
|
|
|
|
|
|
|
|
var readPowerValue = master.Read("x=3;39424", 4).Content;
|
|
|
|
|
if (readPowerValue != null)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<PowerValue>(readPowerValue, FireControlMgr.PowerValue, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 温湿度
|
|
|
|
|
|
|
|
|
|
var readTem = master.Read("s=3;x=3;0", 2).Content;
|
|
|
|
|
if (readTem!=null)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<TemperatureHumidity>(readTem, FireControlMgr.TemperatureHumidity, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
var bytes02 = master.ReadCoil("s=2;x=1;0", 17).Content;//0x01
|
|
|
|
|
var bytes03 = master.Read("s=2;x=3;1", 3).Content;//0x03 读1 3
|
|
|
|
|
var bytes04 = master.Read("s=2;x=3;257", 383).Content;//0x03 读256 383
|
|
|
|
|
var bytes05 = master.Read("s=2;x=4;1", 115).Content;//0x04 可以
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<byte> bytes06=new List<byte>();//= master.BatchReadHolderRegister(0x0800, 2048);//0x04 可以
|
|
|
|
|
var bytesAdd1 = master.BatchReadHolderRegister(0x0800, 1000);//0x04 可以
|
|
|
|
|
var bytesAdd2 = master.BatchReadHolderRegister(3048, 1048);//0x04 可以
|
|
|
|
|
var bytesAdd1 = master.Read("s=2;x=4;2048", 1000).Content;//0x04 可以
|
|
|
|
|
var bytesAdd2 = master.Read("s=2;x=4;3048", 1048).Content;//0x04 可以
|
|
|
|
|
if (bytesAdd1 != null && bytesAdd2 != null)
|
|
|
|
|
{
|
|
|
|
|
bytes06.AddRange(bytesAdd1);
|
|
|
|
@ -40,15 +70,13 @@ public class FireControlClient: ModbusTcpMaster
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var bytes07 = master.BatchReadHolderRegister(0x1000, 32);//0x04 可以
|
|
|
|
|
var bytes08 = master.BatchReadHolderRegister(0x0000, 134);//0x05 写
|
|
|
|
|
var bytes09 = master.BatchReadHolderRegister(0x0100, 64);//0x06 写
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var bytes07 = master.Read("s=2;x=4;4096", 32).Content;//0x04 可以
|
|
|
|
|
var bytes08 = master.Read("s=2;x=5;0", 134).Content;//0x05 写
|
|
|
|
|
var bytes09 = master.Read("s=2;x=6;256", 64).Content;//0x06 写
|
|
|
|
|
|
|
|
|
|
if (bytes02 != null)
|
|
|
|
|
{
|
|
|
|
|
Log.Info("fire read bytes02 success");
|
|
|
|
|
//ModbusDecoder.Decode<Subzone2Resp>(bytes02, FireControlMgr.Subzone2Resp, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
FireControlMgr.Subzone2.GiveAnAlarm.Value = bytes02[0];
|
|
|
|
|
FireControlMgr.Subzone2.NumberOfFailures.Value = bytes02[1];
|
|
|
|
|
FireControlMgr.Subzone2.SoundSuppression.Value = bytes02[2];
|
|
|
|
@ -67,88 +95,174 @@ public class FireControlClient: ModbusTcpMaster
|
|
|
|
|
FireControlMgr.Subzone2.AudibleVisualAlarmStatus.Value = bytes02[15];
|
|
|
|
|
FireControlMgr.Subzone2.DeflatedDoNotEnter.Value = bytes02[16];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"fire read bytes02 erroe{e}");
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (bytes03 != null)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<Subzone3>(bytes03, FireControlMgr.Subzone3, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"fire read bytes03 erroe{e}");
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (bytes04 != null)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<Subzone4>(bytes04, FireControlMgr.Subzone4, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
List<string> faultList = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"fire read bytes04 erroe{e}");
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber01.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber02.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber03.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber04.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber05.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber06.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber07.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber08.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber09.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber10.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber11.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber12.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber13.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber14.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber15.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber16.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber17.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber18.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber19.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber20.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber21.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber22.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber23.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber24.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber25.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber26.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber27.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber28.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber29.Value.ToString()},
|
|
|
|
|
{FireControlMgr.Subzone4.EquipmentNumber30.Value.ToString()},
|
|
|
|
|
};
|
|
|
|
|
SaveAlarmInfo(faultList);
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (bytes05 != null)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<Subzone5>(bytes05, FireControlMgr.Subzone5, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"fire read bytes05 erroe{e}");
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (bytes06 != null)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<Subzone6>(bytes06.ToArray(), FireControlMgr.Subzone6, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"fire read bytes06 erroe{e}");
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (bytes07 != null)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<Subzone7>(bytes07, FireControlMgr.Subzone7, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*if (bytes08 != null)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<Subzone8>(bytes08, FireControlMgr.Subzone8, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
|
|
if (bytes09 != null)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"fire read bytes07 erroe{e}");
|
|
|
|
|
ModbusDecoder.Decode<Subzone9>(bytes09, FireControlMgr.Subzone9, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
|
|
|
|
|
private void SaveAlarmInfo(List<string> lstAlarm)
|
|
|
|
|
{
|
|
|
|
|
if (bytes08 != null)
|
|
|
|
|
if (lstAlarm.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<Subzone8>(bytes08, FireControlMgr.Subzone8, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
#region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录
|
|
|
|
|
|
|
|
|
|
var lstEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipTypeCode == (int)EquipmentType.Fire);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (errorCode != "0")
|
|
|
|
|
{
|
|
|
|
|
EquipAlarmDefine? alarmDefine =
|
|
|
|
|
EquipAlarmDefineRepository.QueryByClause(i=>i.EquipTypeCode==(int)EquipmentType.Fire&&i.ErrorCode==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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"fire read bytes08 erroe{e}");
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
|
|
|
|
|
if (uniqueToList2.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
if (bytes09 != null)
|
|
|
|
|
//这些是要清除实时报警,并且处理记录的。
|
|
|
|
|
// 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象
|
|
|
|
|
List<EquipAlarmRecord> filteredObjectList = lstEquipAlarmRecord
|
|
|
|
|
.Where(obj => uniqueToList2.Contains(obj.ErrorCode))
|
|
|
|
|
.ToList();
|
|
|
|
|
foreach (var VARIABLE in filteredObjectList)
|
|
|
|
|
{
|
|
|
|
|
ModbusDecoder.Decode<Subzone9>(bytes09, FireControlMgr.Subzone9, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#region 没报警把已处理记录更新并删除实时报警
|
|
|
|
|
|
|
|
|
|
var lstEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipTypeCode == 3);
|
|
|
|
|
if (lstEquipAlarmRecord.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"fire read bytes02 erroe{e}");
|
|
|
|
|
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(lstEquipAlarmRecord);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|