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.

83 lines
3.2 KiB

using HslCommunication;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Const;
using HybirdFrameworkDriver.ModbusTcpMaster;
using Service.HelpRight.ElectricMeter;
using Service.Ups.Client;
using Service.Ups.UpsMsg;
namespace Service.Help.ElectricMeter.ElectricClient;
[Scope]
public class ElectricClientLeft:ModbusTcpMaster
{
public ElectricClientLeft()
{
ReadAction = BatchRead;
Ip = "172.0.20.58";
Port = 502;
Duration = 1000;
AutoReConnect = true;
ByteSeq = EndingConst.ByteSeq.BA;
WordSeq= EndingConst.WordSeq.CD;
}
/// <summary>
/// 读取数据
/// 左1充电机电表 60
/// 左2充电机电表 61
/// 左3充电机电表 62
/// 左4充电机电表 63
/// 左5充电机电表 71
/// 左6充电机电表 72
/// 左7充电机电表 73
/// 左8充电机电表 74
/// </summary>
/// <param name="master"></param>
/// <returns></returns>
private bool BatchRead(ModbusTcpMaster master)
{
OperateResult<byte[]> bytes01 = master.Read("s=60;4106", (ushort)10);
OperateResult<byte[]> bytes02 = master.Read("s=61;4106", (ushort)10);
OperateResult<byte[]> bytes03 = master.Read("s=62;4106", (ushort)10);
OperateResult<byte[]> bytes04 = master.Read("s=63;4106", (ushort)10);
OperateResult<byte[]> bytes05 = master.Read("s=71;4106", (ushort)10);
OperateResult<byte[]> bytes06 = master.Read("s=72;4106", (ushort)10);
OperateResult<byte[]> bytes07 = master.Read("s=73;4106", (ushort)10);
OperateResult<byte[]> bytes08 = master.Read("s=74;4106", (ushort)10);
if (bytes01.Content != null)
{
ModbusDecoder.Decode<ElectricMsg>(bytes01.Content, ElectricMgr.ElectricMsg11, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes02.Content != null)
{
ModbusDecoder.Decode<ElectricMsg>(bytes02.Content, ElectricMgr.ElectricMsg12, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes03.Content != null)
{
ModbusDecoder.Decode<ElectricMsg>(bytes03.Content, ElectricMgr.ElectricMsg13, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes04.Content != null)
{
ModbusDecoder.Decode<ElectricMsg>(bytes04.Content, ElectricMgr.ElectricMsg14, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes05.Content != null)
{
ModbusDecoder.Decode<ElectricMsg>(bytes05.Content, ElectricMgr.ElectricMsg15, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes06.Content != null)
{
ModbusDecoder.Decode<ElectricMsg>(bytes06.Content, ElectricMgr.ElectricMsg16, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes07.Content != null)
{
ModbusDecoder.Decode<ElectricMsg>(bytes07.Content, ElectricMgr.ElectricMsg17, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes08.Content != null)
{
ModbusDecoder.Decode<ElectricMsg>(bytes08.Content, ElectricMgr.ElectricMsg18, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
return true;
}
}