parent
09408ae18b
commit
df071df52f
@ -0,0 +1,86 @@
|
||||
using HybirdFrameworkCore.Const;
|
||||
using HybirdFrameworkDriver.ModbusTcpMaster;
|
||||
using Service.UpsAfrica.Msg;
|
||||
|
||||
namespace Service.UpsAfrica.Client;
|
||||
|
||||
public class UpsAfricaClient: ModbusTcpMaster
|
||||
{
|
||||
public UpsAfricaClient()
|
||||
{
|
||||
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;
|
||||
|
||||
var bytes01 = master.Read("x=3;48", 2).Content;
|
||||
if (bytes01 != null)
|
||||
{
|
||||
UpsAfricaMgr.DataValidityTime = DateTime.Now;
|
||||
|
||||
ModbusDecoder.Decode<UpsIndex30>(bytes01, UpsAfricaMgr.UpsIndex30, EndingConst.ByteSeq.AB,
|
||||
EndingConst.WordSeq.DC);
|
||||
resul = true;
|
||||
}
|
||||
|
||||
var bytes02 = master.Read("x=3;64", 17).Content;
|
||||
if (bytes02 != null)
|
||||
{
|
||||
UpsAfricaMgr.DataValidityTime = DateTime.Now;
|
||||
|
||||
ModbusDecoder.Decode<UpsIndex40>(bytes02, UpsAfricaMgr.UpsIndex40, EndingConst.ByteSeq.AB,
|
||||
EndingConst.WordSeq.DC);
|
||||
resul = true;
|
||||
}
|
||||
|
||||
var bytes03 = master.Read("x=3;80", 4).Content;
|
||||
if (bytes03 != null)
|
||||
{
|
||||
UpsAfricaMgr.DataValidityTime = DateTime.Now;
|
||||
|
||||
ModbusDecoder.Decode<UpsIndex50>(bytes03, UpsAfricaMgr.UpsIndex50, EndingConst.ByteSeq.AB,
|
||||
EndingConst.WordSeq.DC);
|
||||
resul = true;
|
||||
}
|
||||
|
||||
var bytes04 = master.Read("x=3;96", 8).Content;
|
||||
if (bytes04 != null)
|
||||
{
|
||||
UpsAfricaMgr.DataValidityTime = DateTime.Now;
|
||||
|
||||
ModbusDecoder.Decode<UpsIndex60>(bytes04, UpsAfricaMgr.UpsIndex60, EndingConst.ByteSeq.AB,
|
||||
EndingConst.WordSeq.DC);
|
||||
resul = true;
|
||||
}
|
||||
|
||||
var bytes05 = master.Read("x=3;160", 1).Content;
|
||||
if (bytes05 != null)
|
||||
{
|
||||
UpsAfricaMgr.DataValidityTime = DateTime.Now;
|
||||
|
||||
ModbusDecoder.Decode<UpsIndexA0>(bytes05, UpsAfricaMgr.UpsIndexA0, EndingConst.ByteSeq.AB,
|
||||
EndingConst.WordSeq.DC);
|
||||
resul = true;
|
||||
}
|
||||
|
||||
var bytes06 = master.Read("x=3;192", 1).Content;
|
||||
if (bytes06 != null)
|
||||
{
|
||||
UpsAfricaMgr.DataValidityTime = DateTime.Now;
|
||||
|
||||
ModbusDecoder.Decode<UpsIndexC0>(bytes06, UpsAfricaMgr.UpsIndexC0, EndingConst.ByteSeq.AB,
|
||||
EndingConst.WordSeq.DC);
|
||||
resul = true;
|
||||
}
|
||||
|
||||
return resul;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using HybirdFrameworkCore.Autofac.Attribute;
|
||||
using Service.UpsAfrica.Msg;
|
||||
using HybirdFrameworkCore.Autofac;
|
||||
using Autofac;
|
||||
|
||||
|
||||
namespace Service.UpsAfrica.Client;
|
||||
|
||||
[Scope]
|
||||
public class UpsAfricaMgr
|
||||
{
|
||||
public static UpsAfricaClient? UpsAfricaClient;
|
||||
public static readonly UpsIndex30 UpsIndex30 = new UpsIndex30();
|
||||
public static readonly UpsIndex40 UpsIndex40 = new UpsIndex40();
|
||||
public static readonly UpsIndex50 UpsIndex50 = new UpsIndex50();
|
||||
public static readonly UpsIndex60 UpsIndex60 = new UpsIndex60();
|
||||
public static readonly UpsIndexA0 UpsIndexA0 = new UpsIndexA0();
|
||||
public static readonly UpsIndexC0 UpsIndexC0 = new UpsIndexC0();
|
||||
|
||||
/// <summary>
|
||||
/// 数据有效时间。单位秒
|
||||
/// </summary>
|
||||
static int DataTimeSeconds = 20;
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数据刷新时间
|
||||
/// </summary>
|
||||
public static DateTime DataValidityTime = DateTime.Now;
|
||||
|
||||
public static void UpsInit()
|
||||
{
|
||||
if (UpsAfricaClient == null)
|
||||
{
|
||||
UpsAfricaClient = AppInfo.Container.Resolve<UpsAfricaClient>();
|
||||
}
|
||||
|
||||
Task.Run(() => UpsAfricaClient.Connect());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
using HybirdFrameworkDriver.ModbusTcpMaster;
|
||||
|
||||
namespace Service.UpsAfrica.Msg;
|
||||
|
||||
public class UpsIndexA0
|
||||
{
|
||||
/// <summary>
|
||||
/// 标称电源电压
|
||||
/// </summary>
|
||||
public ModbusProperty<short> NominalMainsVoltage =new(30160,start:0,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 标称电源频率
|
||||
/// </summary>
|
||||
public ModbusProperty<short> NominalMainsFrequency =new(30160,start:1,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 标称电池电压
|
||||
/// </summary>
|
||||
public ModbusProperty<short> NominalCellVoltage =new(30160,start:2,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 最大电源电压
|
||||
/// </summary>
|
||||
public ModbusProperty<short> MaximumMainsVoltage=new(30160,start:3,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 最低电源电压
|
||||
/// </summary>
|
||||
public ModbusProperty<short> MinimumMainsVoltage =new(30160,start:4,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 最大电源频率
|
||||
/// </summary>
|
||||
public ModbusProperty<short> MaximumMainsFrequency =new(30160,start:5,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 最低电源频率
|
||||
/// </summary>
|
||||
public ModbusProperty<short> MinimumMainsFrequency =new(30160,start:6,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 最高电源环境温度
|
||||
/// </summary>
|
||||
public ModbusProperty<short> MaximumMainsAmbientTemperature =new(30160,start:7,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 最低电源环境温度
|
||||
/// </summary>
|
||||
public ModbusProperty<short> MinimumMainsAmbientTemperature=new(30160,start:8,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 电池单元编号
|
||||
/// </summary>
|
||||
public ModbusProperty<short> BatteryCellNumber =new(30160,start:9,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 串联的电池单元数量
|
||||
/// </summary>
|
||||
public ModbusProperty<short> NumberBatteryCellsSeries =new(30160,start:10,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// Y型或Delta型输入变压器
|
||||
/// </summary>
|
||||
public ModbusProperty<short> InputTransformerTypeYDelta =new(30160,start:11,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// LCD显示器输出电压线或相
|
||||
/// </summary>
|
||||
public ModbusProperty<short> LCDDisplayOutputVoltageLinePhase =new(30160,start:12,length:4,type:ModbusDataType.Bit);
|
||||
/// <summary>
|
||||
/// 保留
|
||||
/// </summary>
|
||||
public ModbusProperty<short> Reserved=new(30160,start:13,length:4,type:ModbusDataType.Bit);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using HybirdFrameworkDriver.ModbusTcpMaster;
|
||||
|
||||
namespace Service.UpsAfrica.Msg;
|
||||
|
||||
public class UpsIndexC0
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取/设置波特率
|
||||
/// </summary>
|
||||
public ModbusProperty<short> GettingSettingBaudRate=new(30192,start:0,length:4,type:ModbusDataType.Bit);
|
||||
|
||||
}
|
Loading…
Reference in new issue