You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
14 KiB

using Autofac;
using Common.Const;
using Entity.DbModel.Station;
using Furion;
using HslCommunication;
using HslCommunication.ModBus;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Const;
using HybirdFrameworkDriver.ModbusTcpMaster;
using Repository.Station;
using Service.Execute.Utils;
using Service.Ups.Msg;
namespace Service.Ups;
[Scope]
public class UpsClient: ModbusTcpMaster
{
public EquipAlarmDefineRepository _equipAlarmDefineRepository=AppInfo.Container.Resolve<EquipAlarmDefineRepository>();
public EquipAlarmRecordRepository _equipAlarmRecordRepository=AppInfo.Container.Resolve<EquipAlarmRecordRepository>();
public EquipAlarmProcessRecordRepository _equipAlarmProcessRecordRepository=AppInfo.Container.Resolve<EquipAlarmProcessRecordRepository>();
public UpsClient()
{
ReadAction = BatchRead;
Ip = "192.168.3.100";
Port = 23;
Duration = 1000;
AutoReConnect = true;
ByteSeq = EndingConst.ByteSeq.BA;
WordSeq= EndingConst.WordSeq.CD;
}
private bool BatchRead(ModbusTcpMaster master)
{
bool resul = Connected;
/*ModbusTcpNet _client = new ModbusTcpNet(master.Ip, master.Port, 0x01);
OperateResult<byte[]> operateResult01 = _client.Read("x=3;" + 1, (ushort)81);
OperateResult<byte[]> operateResult02 = _client.Read("x=3;" + 1, (ushort)81);
*/
//0x03
var bytes02 = master.Read("x=3;1", 80).Content;
if (bytes02 != null)
{
UpsMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<UpsRemoteComm>(bytes02, UpsMgr.UpsRemoteComm, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
}
//0x04
var bytes01 = master.BatchReadInputRegister(81, 160);
if (bytes01 != null)
{
UpsMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<UpsTelemetering>(bytes01, UpsMgr.UpsTelemetering, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
Dictionary<int, bool> faultDic = new();
faultDic.Add(1, UpsMgr.UpsTelemetering.InputFail.Value == 1 ? true : false);
faultDic.Add(2, UpsMgr.UpsTelemetering.BypassSequenceFail.Value == 1 ? true : false);
faultDic.Add(3, UpsMgr.UpsTelemetering.BypassVoltFail.Value == 1 ? true : false);
faultDic.Add(4, UpsMgr.UpsTelemetering.BYpassFail.Value == 1 ? true : false);
faultDic.Add(5, UpsMgr.UpsTelemetering.BypassOverLoad.Value == 1 ? true : false);
faultDic.Add(6, UpsMgr.UpsTelemetering.BypassOverLoadTimeout.Value == 1 ? true : false);
faultDic.Add(7, UpsMgr.UpsTelemetering.BypassUntrack.Value == 1 ? true : false);
faultDic.Add(8, UpsMgr.UpsTelemetering.OutputShorted.Value == 1 ? true : false);
faultDic.Add(9, UpsMgr.UpsTelemetering.BatteryEod.Value == 1 ? true : false);
faultDic.Add(10, UpsMgr.UpsTelemetering.BypassFanFail.Value == 1 ? true : false);
faultDic.Add(11, UpsMgr.UpsTelemetering.CtWeldReserve.Value == 1 ? true : false);
faultDic.Add(12, UpsMgr.UpsTelemetering.Elector.Value == 1 ? true : false);
faultDic.Add(13, UpsMgr.UpsTelemetering.Unit1RecFail.Value == 1 ? true : false);
faultDic.Add(14, UpsMgr.UpsTelemetering.Unit1InvFail.Value == 1 ? true : false);
faultDic.Add(15, UpsMgr.UpsTelemetering.Unit1RecOverTemp.Value == 1 ? true : false);
faultDic.Add(16, UpsMgr.UpsTelemetering.Unit1FanFail.Value == 1 ? true : false);
faultDic.Add(17, UpsMgr.UpsTelemetering.Unit1IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(18, UpsMgr.UpsTelemetering.Unit1IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(19, UpsMgr.UpsTelemetering.Unit1IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(20, UpsMgr.UpsTelemetering.Unit1IvnProtect.Value == 1 ? true : false);
faultDic.Add(21, UpsMgr.UpsTelemetering.Unit2RecFail.Value == 1 ? true : false);
faultDic.Add(22, UpsMgr.UpsTelemetering.Unit2InvFail.Value == 1 ? true : false);
faultDic.Add(23, UpsMgr.UpsTelemetering.Unit2RecOverTemp.Value == 1 ? true : false);
faultDic.Add(24, UpsMgr.UpsTelemetering.Unit2FanFail.Value == 1 ? true : false);
faultDic.Add(25, UpsMgr.UpsTelemetering.Unit2IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(26, UpsMgr.UpsTelemetering.Unit2IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(27, UpsMgr.UpsTelemetering.Unit2IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(28, UpsMgr.UpsTelemetering.Unit2IvnProtect.Value == 1 ? true : false);
faultDic.Add(29, UpsMgr.UpsTelemetering.Unit3RecFail.Value == 1 ? true : false);
faultDic.Add(30, UpsMgr.UpsTelemetering.Unit3InvFail.Value == 1 ? true : false);
faultDic.Add(31, UpsMgr.UpsTelemetering.Unit3RecOverTemp.Value == 1 ? true : false);
faultDic.Add(32, UpsMgr.UpsTelemetering.Unit3FanFail.Value == 1 ? true : false);
faultDic.Add(33, UpsMgr.UpsTelemetering.Unit3IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(34, UpsMgr.UpsTelemetering.Unit3IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(35, UpsMgr.UpsTelemetering.Unit3IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(36, UpsMgr.UpsTelemetering.Unit3IvnProtect.Value == 1 ? true : false);
faultDic.Add(37, UpsMgr.UpsTelemetering.Unit4RecFail.Value == 1 ? true : false);
faultDic.Add(38, UpsMgr.UpsTelemetering.Unit4InvFail.Value == 1 ? true : false);
faultDic.Add(39, UpsMgr.UpsTelemetering.Unit4RecOverTemp.Value == 1 ? true : false);
faultDic.Add(40, UpsMgr.UpsTelemetering.Unit4FanFail.Value == 1 ? true : false);
faultDic.Add(41, UpsMgr.UpsTelemetering.Unit4IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(42, UpsMgr.UpsTelemetering.Unit4IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(43, UpsMgr.UpsTelemetering.Unit4IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(44, UpsMgr.UpsTelemetering.Unit4IvnProtect.Value == 1 ? true : false);
faultDic.Add(45, UpsMgr.UpsTelemetering.Unit5RecFail.Value == 1 ? true : false);
faultDic.Add(46, UpsMgr.UpsTelemetering.Unit5InvFail.Value == 1 ? true : false);
faultDic.Add(47, UpsMgr.UpsTelemetering.Unit5RecOverTemp.Value == 1 ? true : false);
faultDic.Add(48, UpsMgr.UpsTelemetering.Unit5FanFail.Value == 1 ? true : false);
faultDic.Add(49, UpsMgr.UpsTelemetering.Unit5IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(50, UpsMgr.UpsTelemetering.Unit5IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(51, UpsMgr.UpsTelemetering.Unit5IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(52, UpsMgr.UpsTelemetering.Unit5IvnProtect.Value == 1 ? true : false);
faultDic.Add(53, UpsMgr.UpsTelemetering.Unit6RecFail.Value == 1 ? true : false);
faultDic.Add(54, UpsMgr.UpsTelemetering.Unit6InvFail.Value == 1 ? true : false);
faultDic.Add(55, UpsMgr.UpsTelemetering.Unit6RecOverTemp.Value == 1 ? true : false);
faultDic.Add(56, UpsMgr.UpsTelemetering.Unit6FanFail.Value == 1 ? true : false);
faultDic.Add(57, UpsMgr.UpsTelemetering.Unit6IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(58, UpsMgr.UpsTelemetering.Unit6IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(59, UpsMgr.UpsTelemetering.Unit6IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(60, UpsMgr.UpsTelemetering.Unit6IvnProtect.Value == 1 ? true : false);
faultDic.Add(61, UpsMgr.UpsTelemetering.Unit7RecFail.Value == 1 ? true : false);
faultDic.Add(62, UpsMgr.UpsTelemetering.Unit7InvFail.Value == 1 ? true : false);
faultDic.Add(63, UpsMgr.UpsTelemetering.Unit7RecOverTemp.Value == 1 ? true : false);
faultDic.Add(64, UpsMgr.UpsTelemetering.Unit7FanFail.Value == 1 ? true : false);
faultDic.Add(65, UpsMgr.UpsTelemetering.Unit7IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(66, UpsMgr.UpsTelemetering.Unit7IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(67, UpsMgr.UpsTelemetering.Unit7IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(68, UpsMgr.UpsTelemetering.Unit7IvnProtect.Value == 1 ? true : false);
faultDic.Add(69, UpsMgr.UpsTelemetering.Unit8RecFail.Value == 1 ? true : false);
faultDic.Add(70, UpsMgr.UpsTelemetering.Unit8InvFail.Value == 1 ? true : false);
faultDic.Add(71, UpsMgr.UpsTelemetering.Unit8RecOverTemp.Value == 1 ? true : false);
faultDic.Add(72, UpsMgr.UpsTelemetering.Unit8FanFail.Value == 1 ? true : false);
faultDic.Add(73, UpsMgr.UpsTelemetering.Unit8IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(74, UpsMgr.UpsTelemetering.Unit8IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(75, UpsMgr.UpsTelemetering.Unit8IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(76, UpsMgr.UpsTelemetering.Unit8IvnProtect.Value == 1 ? true : false);
faultDic.Add(77, UpsMgr.UpsTelemetering.Unit9RecFail.Value == 1 ? true : false);
faultDic.Add(78, UpsMgr.UpsTelemetering.Unit9InvFail.Value == 1 ? true : false);
faultDic.Add(79, UpsMgr.UpsTelemetering.Unit9RecOverTemp.Value == 1 ? true : false);
faultDic.Add(80, UpsMgr.UpsTelemetering.Unit9FanFail.Value == 1 ? true : false);
faultDic.Add(81, UpsMgr.UpsTelemetering.Unit9IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(82, UpsMgr.UpsTelemetering.Unit9IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(83, UpsMgr.UpsTelemetering.Unit9IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(84, UpsMgr.UpsTelemetering.Unit9IvnProtect.Value == 1 ? true : false);
faultDic.Add(85, UpsMgr.UpsTelemetering.Unit10RecFail.Value == 1 ? true : false);
faultDic.Add(86, UpsMgr.UpsTelemetering.Unit10InvFail.Value == 1 ? true : false);
faultDic.Add(87, UpsMgr.UpsTelemetering.Unit10RecOverTemp.Value == 1 ? true : false);
faultDic.Add(88, UpsMgr.UpsTelemetering.Unit10FanFail.Value == 1 ? true : false);
faultDic.Add(89, UpsMgr.UpsTelemetering.Unit10IvnOverLoad.Value == 1 ? true : false);
faultDic.Add(90, UpsMgr.UpsTelemetering.Unit10IvnOverLoadTimeOut.Value == 1 ? true : false);
faultDic.Add(91, UpsMgr.UpsTelemetering.Unit10IvnOverTemp.Value == 1 ? true : false);
faultDic.Add(92, UpsMgr.UpsTelemetering.Unit10IvnProtect.Value == 1 ? true : false);
FaultHandling(faultDic);
}
return true;
}
/// <summary>
/// 故障处理
/// </summary>
/// <param name="faultDic"></param>
public void FaultHandling(Dictionary<int, bool> faultDic)
{
var EquipAlarmDefineLst =
_equipAlarmDefineRepository.QueryByClauseToList(i => i.EquipTypeCode == (int)EquipmentType.Bms);
foreach (var VARIABLE in faultDic)
{
string errorCode = VARIABLE.Key.ToString();
EquipAlarmRecord equipAlarmRecordSql =
_equipAlarmRecordRepository.QueryByClause(i => i.ErrorCode == errorCode&&i.EquipTypeCode == (int)EquipmentType.Bms);
if (VARIABLE.Value) //有报警
{
if (equipAlarmRecordSql == null)//数据库中没有此报警,这里查询信息添加到数据库
{
EquipAlarmDefine equipAlarmDefine =
EquipAlarmDefineLst.SingleOrDefault(i => i.ErrorCode == VARIABLE.Key.ToString());
if (equipAlarmDefine != null)
{
EquipAlarmRecord equipAlarmRecord = new()
{
EquipTypeCode = equipAlarmDefine.EquipTypeCode,
EquipCode = equipAlarmDefine.EquipCode,
ErrorCode = errorCode,
ErrorLevel = equipAlarmDefine.ErrorLevel,
ErrorMsg = equipAlarmDefine.ErrorMsg,
ProcessMethod = equipAlarmDefine.ProcessMethod,
StartTime = DateTime.Now,
};
_equipAlarmRecordRepository.Insert(equipAlarmRecord);
}
}
}
else
{
if (equipAlarmRecordSql != null) //数据库中没有此报警,这里查询信息添加到数据库
{
EquipAlarmProcessRecord equipAlarmProcessRecord = new()
{
EquipTypeCode = equipAlarmRecordSql.EquipTypeCode,
EquipCode = equipAlarmRecordSql.EquipCode,
ErrorCode = errorCode,
ErrorLevel = equipAlarmRecordSql.ErrorLevel,
ErrorMsg = equipAlarmRecordSql.ErrorMsg,
ProcessMethod = equipAlarmRecordSql.ProcessMethod,
StartTime = equipAlarmRecordSql.StartTime,
ProcessTime = DateTime.Now,
};
_equipAlarmProcessRecordRepository.Insert(equipAlarmProcessRecord);
_equipAlarmRecordRepository.Delete(equipAlarmRecordSql);
}
}
}
}
}