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.

86 lines
2.6 KiB

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;
}
}