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.
44 lines
1.2 KiB
44 lines
1.2 KiB
5 months ago
|
using HybirdFrameworkCore.Const;
|
||
|
using HybirdFrameworkDriver.ModbusTcpMaster;
|
||
|
using Service.Ups.Msg;
|
||
|
|
||
|
namespace Service.Ups;
|
||
|
|
||
|
public class UpsClient: ModbusTcpMaster
|
||
|
{
|
||
|
public UpsClient()
|
||
|
{
|
||
|
ReadAction = BatchRead;
|
||
|
//TODO::UPS ip
|
||
|
Ip = "127.0.0.1";
|
||
|
Port = 502;
|
||
|
Duration = 1000;
|
||
|
AutoReConnect = true;
|
||
|
//TODO::加解码方式
|
||
|
ByteSeq = EndingConst.ByteSeq.BA;
|
||
|
WordSeq= EndingConst.WordSeq.CD;
|
||
|
}
|
||
|
|
||
|
private void BatchRead(ModbusTcpMaster master)
|
||
|
{
|
||
|
//0x03
|
||
|
var bytes01 = master.BatchReadHolderRegister(0, 81);
|
||
|
if (bytes01 != null)
|
||
|
{
|
||
|
UpsMgr.DataValidityTime = DateTime.Now;
|
||
|
|
||
|
ModbusDecoder.Decode<UpsTelemetering>(bytes01, UpsMgr.UpsTelemetering, EndingConst.ByteSeq.AB,
|
||
|
EndingConst.WordSeq.DC);
|
||
|
}
|
||
|
|
||
|
//0x04
|
||
|
var bytes02 = master.BatchReadInputRegister(81, 161);
|
||
|
if (bytes02 != null)
|
||
|
{
|
||
|
UpsMgr.DataValidityTime = DateTime.Now;
|
||
|
|
||
|
ModbusDecoder.Decode<UpsRemoteComm>(bytes01, UpsMgr.UpsRemoteComm, EndingConst.ByteSeq.AB,
|
||
|
EndingConst.WordSeq.DC);
|
||
|
}
|
||
|
}
|
||
|
}
|