From e02a0953e9b4e2646857eb0e0f61416768a2d21f Mon Sep 17 00:00:00 2001
From: ChenYi <296215406@outlook.com>
Date: Wed, 14 May 2025 23:28:44 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=843761=E4=B8=8B=E8=A1=8C?=
=?UTF-8?q?=E9=80=8F=E6=98=8E=E8=BD=AC=E5=8F=91=E5=A4=84=E7=90=86=E9=80=BB?=
=?UTF-8?q?=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../SendData/Telemetry3761PacketBuilder.cs | 11 ++-
.../SendData/Telemetry3761PacketRequest.cs | 11 ++-
.../SendData/Telemetry6452007PacketRequest.cs | 21 ++---
.../T6452007ProtocolPlugin.cs | 1 +
.../Models/SubProtocolBuildRequest.cs | 10 +++
...nergySystemScheduledMeterReadingService.cs | 80 +++++++++++--------
.../BuildSendDatas/Build3761SendData.cs | 4 +-
.../Consts/MeteringPortConst.cs | 24 ++++++
8 files changed, 107 insertions(+), 55 deletions(-)
create mode 100644 shared/JiShe.CollectBus.Common/Consts/MeteringPortConst.cs
diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/SendData/Telemetry3761PacketBuilder.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/SendData/Telemetry3761PacketBuilder.cs
index f8bfa78..18dcbb3 100644
--- a/protocols/JiShe.CollectBus.Protocol.T37612012/SendData/Telemetry3761PacketBuilder.cs
+++ b/protocols/JiShe.CollectBus.Protocol.T37612012/SendData/Telemetry3761PacketBuilder.cs
@@ -1,4 +1,5 @@
-using System.Reflection;
+using System.Data;
+using System.Reflection;
using JiShe.CollectBus.Common.BuildSendDatas;
using JiShe.CollectBus.Common.Enums;
using JiShe.CollectBus.Common.Models;
@@ -259,6 +260,12 @@ namespace JiShe.CollectBus.Protocol.T37612012.SendData
#region AFN10H 数据转发
public static Telemetry3761PacketResponse AFN10_Fn_Send(Telemetry3761PacketRequest request)
{
+
+ var baudRateValue = Build3761SendData.GetBaudreate($"{request.SubRequest.Baudrate}");
+
+ var dataUnit = Build3761SendData.BuildTransparentForwardingSendDataUnit(request.SubRequest.MeteringPort, baudRateValue, request.DataUnit);
+ dataUnit.AddRange(Build3761SendData.GetPW());
+
var reqParameter = new ReqParameter2()
{
AFN = AFN.数据转发,
@@ -275,7 +282,7 @@ namespace JiShe.CollectBus.Protocol.T37612012.SendData
Pn = request.Pn,
Fn = request.Fn
};
- var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter, request.DataUnit);
+ var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter, dataUnit);
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
}
diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/SendData/Telemetry3761PacketRequest.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/SendData/Telemetry3761PacketRequest.cs
index f02efc9..a5d8593 100644
--- a/protocols/JiShe.CollectBus.Protocol.T37612012/SendData/Telemetry3761PacketRequest.cs
+++ b/protocols/JiShe.CollectBus.Protocol.T37612012/SendData/Telemetry3761PacketRequest.cs
@@ -1,4 +1,6 @@
-namespace JiShe.CollectBus.Protocol.T37612012.SendData
+using JiShe.CollectBus.Protocol.Models;
+
+namespace JiShe.CollectBus.Protocol.T37612012.SendData
{
///
/// 构建3761报文参数
@@ -20,8 +22,13 @@
///
public int Pn { get; set; }
+ ///
+ /// 子协议请求
+ ///
+ public SubProtocolBuildRequest SubRequest { get; set; }
+
///
- /// 透明转发单元
+ /// 透明转发数据单元
///
public List DataUnit { get; set; }
}
diff --git a/protocols/JiShe.CollectBus.Protocol.T6452007/SendData/Telemetry6452007PacketRequest.cs b/protocols/JiShe.CollectBus.Protocol.T6452007/SendData/Telemetry6452007PacketRequest.cs
index c367206..b819b91 100644
--- a/protocols/JiShe.CollectBus.Protocol.T6452007/SendData/Telemetry6452007PacketRequest.cs
+++ b/protocols/JiShe.CollectBus.Protocol.T6452007/SendData/Telemetry6452007PacketRequest.cs
@@ -1,23 +1,12 @@
-namespace JiShe.CollectBus.Protocol.T6452007.SendData
+using JiShe.CollectBus.Protocol.Models;
+
+namespace JiShe.CollectBus.Protocol.T6452007.SendData
{
///
/// 构建645报文参数
///
- public class Telemetry6452007PacketRequest
+ public class Telemetry6452007PacketRequest: SubProtocolBuildRequest
{
- ///
- /// 表地址
- ///
- public required string MeterAddress { get; set; }
-
- ///
- /// 密码
- ///
- public required string Password { get; set; }
-
- ///
- /// 操作码
- ///
- public required string ItemCode { get; set; }
+
}
}
diff --git a/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs
index 4f06f5a..f145638 100644
--- a/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs
+++ b/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs
@@ -129,6 +129,7 @@ namespace JiShe.CollectBus.Protocol.T6452007
FocusAddress = request.FocusAddress,
Fn = fn,
Pn = request.Pn,
+ SubRequest = request.SubProtocolRequest,
DataUnit = dataUnit,
});
}
diff --git a/protocols/JiShe.CollectBus.Protocol/Models/SubProtocolBuildRequest.cs b/protocols/JiShe.CollectBus.Protocol/Models/SubProtocolBuildRequest.cs
index 09a5c55..15526e2 100644
--- a/protocols/JiShe.CollectBus.Protocol/Models/SubProtocolBuildRequest.cs
+++ b/protocols/JiShe.CollectBus.Protocol/Models/SubProtocolBuildRequest.cs
@@ -10,6 +10,16 @@
///
public required string MeterAddress { get; set; }
+ ///
+ /// 波特率 default(2400)
+ ///
+ public int Baudrate { get; set; }
+
+ ///
+ /// 计量端口
+ ///
+ public int MeteringPort { get; set; }
+
///
/// 密码
///
diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs
index 025c250..c51a527 100644
--- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs
+++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs
@@ -125,7 +125,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
BrandType = "DTS1980",
MeterType = MeterTypeEnum.Ammeter,
ProjectID = 1,
- MeteringPort = 2,
+ MeteringPort = MeteringPortConst.MeteringPortTwo,
Password = "000000",
});
@@ -145,7 +145,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
BrandType = "DTS1980",
MeterType = MeterTypeEnum.Ammeter,
ProjectID = 1,
- MeteringPort = 2,
+ MeteringPort = MeteringPortConst.MeteringPortTwo,
Password = "000000",
});
@@ -279,37 +279,49 @@ namespace JiShe.CollectBus.ScheduledMeterReading
string currentTimeStr = $"{currentTime:HH:mm}";
try
- {
+ {
#if DEBUG
- var settingInfos = new List();
- settingInfos.Add(new AmmeterAutoValveControlSetting()
+ //电表自动阀控缓存
+ string redisCacheDeviceSettingInfoHashKey = $"redisCacheDeviceSettingInfoHashKey_{SystemType}_{ServerTagName}";
+
+ var settingInfos = FreeRedisProvider.Instance.Get< List> (redisCacheDeviceSettingInfoHashKey);
+ if (settingInfos == null || settingInfos.Count <= 0)
{
- MeterType = MeterTypeEnum.Ammeter,
- AmmerterAddress = "442405000040",
- FocusAddress = "442400040",
- FocusId = 95780,
- ProjectID = 1,
- TripType = "on",
- TripTime = $"{DateTime.Now:HH:mm}",
- MeterId = 127035,
- LoopType = "EachDay",
- EachDayWithout = "周六,周日",
- TimeDensity = 15,
- });
- settingInfos.Add(new AmmeterAutoValveControlSetting()
- {
- MeterType = MeterTypeEnum.Ammeter,
- AmmerterAddress = "442405000039",
- FocusAddress = "442400039",
- FocusId = 69280,
- ProjectID = 1,
- TripType = "on",
- TripTime = $"{DateTime.Now:HH:mm}",
- MeterId = 95594,
- LoopType = "EachDay",
- EachDayWithout = "周六,周日",
- TimeDensity = 15,
- });
+ settingInfos = new List();
+ settingInfos.Add(new AmmeterAutoValveControlSetting()
+ {
+ MeterType = MeterTypeEnum.Ammeter,
+ AmmerterAddress = "442405000040",
+ FocusAddress = "442400040",
+ FocusId = 95780,
+ ProjectID = 1,
+ TripType = "on",
+ TripTime = $"{DateTime.Now:HH:mm}",
+ MeterId = 127035,
+ LoopType = "EachDay",
+ EachDayWithout = "周六,周日",
+ TimeDensity = 15,
+ });
+ settingInfos.Add(new AmmeterAutoValveControlSetting()
+ {
+ MeterType = MeterTypeEnum.Ammeter,
+ AmmerterAddress = "442405000039",
+ FocusAddress = "442400039",
+ FocusId = 69280,
+ ProjectID = 1,
+ TripType = "on",
+ TripTime = $"{DateTime.Now:HH:mm}",
+ MeterId = 95594,
+ LoopType = "EachDay",
+ EachDayWithout = "周六,周日",
+ TimeDensity = 15,
+ });
+
+
+ FreeRedisProvider.Instance.Set(redisCacheDeviceSettingInfoHashKey, settingInfos);
+ }
+
+
#else
//获取电表阀控配置
var settingInfos = await GetAmmeterAutoValveControlSetting(currentTimeStr);
@@ -375,7 +387,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
bool tripStateResult = false;
string itemCode = T37612012PacketItemCodeConst.AFN10HFN01H;
string subItemCode = string.Empty;
- if (settingInfo.TripType.Equals("on"))
+ if (settingInfo.TripType.Equals("on"))//当前电表断闸,需要合闸
{
ammeterInfo.TripState = 0;
tripStateResult = true;
@@ -385,7 +397,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
subItemCode = T6452007PacketItemCodeConst.C1C011B;
}
}
- else if (settingInfo.TripType.Equals("off"))
+ else if (settingInfo.TripType.Equals("off"))//当前电表合闸,需要断闸
{
ammeterInfo.TripState = 1;
tripStateResult = false;
@@ -416,6 +428,8 @@ namespace JiShe.CollectBus.ScheduledMeterReading
MeterAddress = ammeterInfo.MeterAddress,
Password = ammeterInfo.Password,
ItemCode = subItemCode,
+ Baudrate = ammeterInfo.Baudrate,
+ MeteringPort = ammeterInfo.MeteringPort
}
});
diff --git a/shared/JiShe.CollectBus.Common/BuildSendDatas/Build3761SendData.cs b/shared/JiShe.CollectBus.Common/BuildSendDatas/Build3761SendData.cs
index 76f6b88..2d815da 100644
--- a/shared/JiShe.CollectBus.Common/BuildSendDatas/Build3761SendData.cs
+++ b/shared/JiShe.CollectBus.Common/BuildSendDatas/Build3761SendData.cs
@@ -1362,7 +1362,7 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
/// 等待报文超时时间/s
/// 等待字节超时时间/ms
///
- private static List BuildTransparentForwardingSendDataUnit(int port, int baudRate, List datas, StopBit stopBit = StopBit.Stop1, Parity parity = Parity.Even, DataBit dataBit = DataBit.D8,
+ public static List BuildTransparentForwardingSendDataUnit(int port, int baudRate, List datas, StopBit stopBit = StopBit.Stop1, Parity parity = Parity.Even, DataBit dataBit = DataBit.D8,
int waitContentTimeout = 100, int waitByteTimeout = 100)
{
var dataUnit = new List();
@@ -1591,7 +1591,7 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
//AUX=消息认证码字段(PW,16个字节)
- private static List GetPW()
+ public static List GetPW()
{
var str = "00";
var pWList = Enumerable.Repeat(str, pWLen).ToList();
diff --git a/shared/JiShe.CollectBus.Common/Consts/MeteringPortConst.cs b/shared/JiShe.CollectBus.Common/Consts/MeteringPortConst.cs
new file mode 100644
index 0000000..c65b027
--- /dev/null
+++ b/shared/JiShe.CollectBus.Common/Consts/MeteringPortConst.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JiShe.CollectBus.Common.Consts
+{
+ ///
+ /// 计量端口常量
+ ///
+ public class MeteringPortConst
+ {
+ ///
+ /// 计量端口1
+ ///
+ public const int MeteringPortOne = 1;
+
+ ///
+ /// 计量端口2
+ ///
+ public const int MeteringPortTwo = 2;
+ }
+}