mirror of
https://github.com/ThingsGateway/ThingsGateway.git
synced 2026-10-29 04:16:49 +08:00
release:6.0.2.16
refactor: 优化DTU模式采集
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>6.0.2.15</Version>
|
||||
<Version>6.0.2.16</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -41,6 +41,11 @@ public class Dlt645_2007Master : ProtocolBase, IDtu
|
||||
/// <inheritdoc/>
|
||||
public string Station { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认Dtu注册包,utf-8字符串
|
||||
/// </summary>
|
||||
public string DtuId { get; set; } = "TEST";
|
||||
|
||||
/// <summary>
|
||||
/// 客户端连接滑动过期时间(TCP服务通道时)
|
||||
/// </summary>
|
||||
@@ -115,7 +120,7 @@ public class Dlt645_2007Master : ProtocolBase, IDtu
|
||||
{
|
||||
try
|
||||
{
|
||||
var dAddress = Dlt645_2007Address.ParseFrom(address);
|
||||
var dAddress = Dlt645_2007Address.ParseFrom(address, Station, DtuId);
|
||||
var commandResult = Dlt645Helper.GetDlt645_2007Command(dAddress, (byte)ControlCode.Read, Station);
|
||||
return await SendThenReturnAsync(dAddress.SocketId, commandResult, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -139,7 +144,7 @@ public class Dlt645_2007Master : ProtocolBase, IDtu
|
||||
|
||||
var data = DataTransUtil.SpliceArray(Password.ByHexStringToBytes(), OperCode.ByHexStringToBytes());
|
||||
string[] strArray = value.SplitStringBySemicolon();
|
||||
var dAddress = Dlt645_2007Address.ParseFrom(address);
|
||||
var dAddress = Dlt645_2007Address.ParseFrom(address, Station, DtuId);
|
||||
var commandResult = Dlt645Helper.GetDlt645_2007Command(dAddress, (byte)ControlCode.Write, Station, data, strArray);
|
||||
return await SendThenReturnAsync(dAddress.SocketId, commandResult, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ using ThingsGateway.Foundation.Extension.String;
|
||||
|
||||
using TouchSocket.Core;
|
||||
|
||||
using static System.Collections.Specialized.BitVector32;
|
||||
|
||||
namespace ThingsGateway.Foundation.Dlt645;
|
||||
|
||||
/// <summary>
|
||||
@@ -76,7 +78,7 @@ public class Dlt645_2007Address
|
||||
/// <summary>
|
||||
/// 解析地址
|
||||
/// </summary>
|
||||
public static Dlt645_2007Address ParseFrom(string address, bool isCache = true)
|
||||
public static Dlt645_2007Address ParseFrom(string address, string defaultStation = null, string dtuid = null, bool isCache = true)
|
||||
{
|
||||
var cacheKey = $"{nameof(ParseFrom)}_{typeof(Dlt645_2007Address).FullName}_{typeof(Dlt645_2007Address).TypeHandle.Value}_{address}";
|
||||
if (isCache)
|
||||
@@ -84,6 +86,15 @@ public class Dlt645_2007Address
|
||||
return dAddress.Map();
|
||||
|
||||
Dlt645_2007Address dlt645_2007Address = new();
|
||||
if (defaultStation != null)
|
||||
{
|
||||
if (defaultStation.IsNullOrEmpty()) defaultStation = string.Empty;
|
||||
if (defaultStation.Length < 12)
|
||||
defaultStation = defaultStation.PadLeft(12, '0');
|
||||
dlt645_2007Address.Station = defaultStation.ByHexStringToBytes().Reverse().ToArray();
|
||||
}
|
||||
if (dtuid != null)
|
||||
dlt645_2007Address.SocketId = dtuid;
|
||||
byte[] array;
|
||||
array = Array.Empty<byte>();
|
||||
if (address.IndexOf(';') < 0)
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
{
|
||||
"ThingsGateway.Foundation.Dlt645.Dlt645_2007Master": {
|
||||
"FEHead": "Front-end identifier in message header",
|
||||
"OperCode": "Operator code",
|
||||
"Password": "Write password",
|
||||
"Station": "Communication address",
|
||||
"CheckClearTime": "Connection sliding expiration time",
|
||||
"HeartbeatHexString": "Heartbeat detection",
|
||||
"FEHead": "FEHead",
|
||||
"OperCode": "OperCode",
|
||||
"Password": "Password",
|
||||
"Station": "Station",
|
||||
"DtuId": "DtuId",
|
||||
"CheckClearTime": "CheckClearTime",
|
||||
"HeartbeatHexString": "HeartbeatHexString",
|
||||
|
||||
"CacheTimeout": "Packet Assembly Cache Time",
|
||||
"SendDelayTime": "Send Delay Time",
|
||||
"EndianType": "Parsing Rules",
|
||||
"Timeout": "Read/Write Timeout",
|
||||
"ConnectTimeout": "Connection Timeout",
|
||||
"IsStringReverseByteWord": "String Byte/Word Reversal"
|
||||
"CacheTimeout": "CacheTimeout",
|
||||
"SendDelayTime": "SendDelayTime",
|
||||
"EndianType": "EndianType",
|
||||
"Timeout": "Timeout",
|
||||
"ConnectTimeout": "ConnectTimeout",
|
||||
"IsStringReverseByteWord": "IsStringReverseByteWord"
|
||||
},
|
||||
|
||||
"ThingsGateway.Foundation.Dlt645.DltResource": {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"OperCode": "操作员代码",
|
||||
"Password": "写入密码",
|
||||
"Station": "通讯地址",
|
||||
"DtuId": "Dtu注册包",
|
||||
"CheckClearTime": "连接滑动过期时间",
|
||||
"HeartbeatHexString": "心跳检测",
|
||||
|
||||
|
||||
@@ -119,10 +119,10 @@ public class ModbusAddress
|
||||
/// <summary>
|
||||
/// 解析地址
|
||||
/// </summary>
|
||||
public static ModbusAddress? ParseFrom(string address, byte? station = null, bool isCache = true)
|
||||
public static ModbusAddress? ParseFrom(string address, byte? station = null, string dtuid = null, bool isCache = true)
|
||||
{
|
||||
if (address.IsNullOrWhiteSpace()) { return null; }
|
||||
var cacheKey = $"{nameof(ParseFrom)}_{typeof(ModbusAddress).FullName}_{typeof(ModbusAddress).TypeHandle.Value}_{station}_{address}";
|
||||
var cacheKey = $"{nameof(ParseFrom)}_{typeof(ModbusAddress).FullName}_{typeof(ModbusAddress).TypeHandle.Value}_{station}_{dtuid}_{address}";
|
||||
if (isCache)
|
||||
if (MemoryCache.Instance.TryGetValue(cacheKey, out ModbusAddress mAddress))
|
||||
return mAddress.Map();
|
||||
@@ -130,6 +130,8 @@ public class ModbusAddress
|
||||
var modbusAddress = new ModbusAddress();
|
||||
if (station != null)
|
||||
modbusAddress.Station = station.Value;
|
||||
if (dtuid != null)
|
||||
modbusAddress.SocketId = dtuid;
|
||||
if (address.IndexOf(';') < 0)
|
||||
{
|
||||
Address(address);
|
||||
|
||||
@@ -22,8 +22,10 @@ public class PackHelper
|
||||
/// <param name="deviceVariables"></param>
|
||||
/// <param name="maxPack">最大打包长度</param>
|
||||
/// <param name="defaultIntervalTime">默认间隔时间</param>
|
||||
/// <param name="station">默认站点</param>
|
||||
/// <param name="dtuid">默认dtuid</param>
|
||||
/// <returns></returns>
|
||||
public static List<T> LoadSourceRead<T>(IProtocol device, IEnumerable<IVariable> deviceVariables, int maxPack, int defaultIntervalTime) where T : IVariableSource, new()
|
||||
public static List<T> LoadSourceRead<T>(IProtocol device, IEnumerable<IVariable> deviceVariables, int maxPack, int defaultIntervalTime, byte? station = null, string dtuid = null) where T : IVariableSource, new()
|
||||
{
|
||||
// 检查参数是否为空
|
||||
if (deviceVariables == null)
|
||||
@@ -80,7 +82,7 @@ public class PackHelper
|
||||
|
||||
// 解析地址,并设置字节长度
|
||||
var address = it.RegisterAddress;
|
||||
var result = ModbusAddress.ParseFrom(address, isCache: false);
|
||||
var result = ModbusAddress.ParseFrom(address, station, dtuid, isCache: false);
|
||||
result.ByteLength = lastLen;
|
||||
return result;
|
||||
}));
|
||||
|
||||
@@ -1,31 +1,32 @@
|
||||
{
|
||||
"ThingsGateway.Foundation.Modbus.ModbusMaster": {
|
||||
"ModbusType": "Modbus Type",
|
||||
"Station": "Default Station Number",
|
||||
"CheckClearTime": "Connection Sliding Expiration Time",
|
||||
"HeartbeatHexString": "Heartbeat Detection (Uppercase Hexadecimal String)",
|
||||
"ModbusType": "ModbusType",
|
||||
"Station": "Station",
|
||||
"DtuId": "DtuId",
|
||||
"CheckClearTime": "CheckClearTime",
|
||||
"HeartbeatHexString": "HeartbeatHexString",
|
||||
|
||||
"CacheTimeout": "Packet Assembly Cache Time",
|
||||
"SendDelayTime": "Send Delay Time",
|
||||
"EndianType": "Parsing Rules",
|
||||
"Timeout": "Read/Write Timeout",
|
||||
"ConnectTimeout": "Connection Timeout",
|
||||
"IsStringReverseByteWord": "String Byte/Word Reversal"
|
||||
"CacheTimeout": "CacheTimeout",
|
||||
"SendDelayTime": "SendDelayTime",
|
||||
"EndianType": "EndianType",
|
||||
"Timeout": "Timeout",
|
||||
"ConnectTimeout": "ConnectTimeout",
|
||||
"IsStringReverseByteWord": "IsStringReverseByteWord"
|
||||
},
|
||||
"ThingsGateway.Foundation.Modbus.ModbusSlave": {
|
||||
"ModbusType": "Modbus Type",
|
||||
"Station": "Default Station Number",
|
||||
"CheckClearTime": "Connection Sliding Expiration Time",
|
||||
"MulStation": "Multiple Stations",
|
||||
"IsWriteMemory": "Immediate Memory Write",
|
||||
"MaxClientCount": "Maximum Connection Count",
|
||||
"ModbusType": "ModbusType",
|
||||
"Station": "Station",
|
||||
"CheckClearTime": "CheckClearTime",
|
||||
"MulStation": "MulStation",
|
||||
"IsWriteMemory": "IsWriteMemory",
|
||||
"MaxClientCount": "MaxClientCount",
|
||||
|
||||
"CacheTimeout": "Packet Assembly Cache Time",
|
||||
"SendDelayTime": "Send Delay Time",
|
||||
"EndianType": "Parsing Rules",
|
||||
"Timeout": "Read/Write Timeout",
|
||||
"ConnectTimeout": "Connection Timeout",
|
||||
"IsStringReverseByteWord": "String Byte/Word Reversal"
|
||||
"CacheTimeout": "CacheTimeout",
|
||||
"SendDelayTime": "SendDelayTime",
|
||||
"EndianType": "EndianType",
|
||||
"Timeout": "Timeout",
|
||||
"ConnectTimeout": "ConnectTimeout",
|
||||
"IsStringReverseByteWord": "IsStringReverseByteWord"
|
||||
},
|
||||
|
||||
"ThingsGateway.Foundation.Modbus.ModbusResource": {
|
||||
@@ -45,4 +46,4 @@
|
||||
"ValueOverlimit": "{0} cannot exceed {1}",
|
||||
"CrcError": "CRC check failed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"ThingsGateway.Foundation.Modbus.ModbusMaster": {
|
||||
"ModbusType": "Modbus类型",
|
||||
"Station": "默认站号",
|
||||
"Station": "站号",
|
||||
"DtuId": "Dtu注册包",
|
||||
"CheckClearTime": "连接滑动过期时间",
|
||||
"HeartbeatHexString": "心跳检测(大写16进制字符串)",
|
||||
|
||||
@@ -44,4 +45,4 @@
|
||||
"ValueOverlimit": "{0} 不能超过 {1}",
|
||||
"CrcError": "Crc校验失败"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,11 @@ public partial class ModbusMaster : ProtocolBase, IDtu
|
||||
/// </summary>
|
||||
public byte Station { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 默认Dtu注册包,utf-8字符串
|
||||
/// </summary>
|
||||
public string DtuId { get; set; } = "TEST";
|
||||
|
||||
/// <summary>
|
||||
/// 客户端连接滑动过期时间(TCP服务通道时)
|
||||
/// </summary>
|
||||
@@ -144,7 +149,7 @@ public partial class ModbusMaster : ProtocolBase, IDtu
|
||||
/// <inheritdoc/>
|
||||
public override List<T> LoadSourceRead<T>(IEnumerable<IVariable> deviceVariables, int maxPack, int defaultIntervalTime)
|
||||
{
|
||||
return PackHelper.LoadSourceRead<T>(this, deviceVariables, maxPack, defaultIntervalTime);
|
||||
return PackHelper.LoadSourceRead<T>(this, deviceVariables, maxPack, defaultIntervalTime, Station, DtuId);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -152,7 +157,7 @@ public partial class ModbusMaster : ProtocolBase, IDtu
|
||||
{
|
||||
try
|
||||
{
|
||||
var mAddress = ModbusAddress.ParseFrom(address, Station);
|
||||
var mAddress = ModbusAddress.ParseFrom(address, Station, DtuId);
|
||||
var commandResult = ModbusHelper.GetReadModbusCommand(mAddress, (ushort)length);
|
||||
return await SendThenReturnAsync(mAddress.SocketId, commandResult, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -167,7 +172,7 @@ public partial class ModbusMaster : ProtocolBase, IDtu
|
||||
{
|
||||
try
|
||||
{
|
||||
var mAddress = ModbusAddress.ParseFrom(address, Station);
|
||||
var mAddress = ModbusAddress.ParseFrom(address, Station, DtuId);
|
||||
value = value.ArrayExpandToLengthEven();
|
||||
byte[]? commandResult = null;
|
||||
//功能码或实际长度
|
||||
@@ -188,7 +193,7 @@ public partial class ModbusMaster : ProtocolBase, IDtu
|
||||
{
|
||||
try
|
||||
{
|
||||
var mAddress = ModbusAddress.ParseFrom(address, Station);
|
||||
var mAddress = ModbusAddress.ParseFrom(address, Station, DtuId);
|
||||
//功能码或实际长度
|
||||
if (value.Length > 1 || mAddress.WriteFunction == 15)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,7 @@ public class Dlt645_2007Master : CollectBase
|
||||
_plc = new(channel)
|
||||
{
|
||||
EndianType = _driverPropertys.EndianType,
|
||||
DtuId = _driverPropertys.DtuId,
|
||||
SendDelayTime = _driverPropertys.SendDelayTime,
|
||||
CacheTimeout = _driverPropertys.CacheTimeout,
|
||||
ConnectTimeout = _driverPropertys.ConnectTimeout,
|
||||
|
||||
@@ -67,6 +67,12 @@ public class Dlt645_2007MasterProperty : CollectPropertyBase
|
||||
[DynamicProperty]
|
||||
public string Station { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认DtuId
|
||||
/// </summary>
|
||||
[DynamicProperty]
|
||||
public string? DtuId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"OperCode": "OperCode",
|
||||
"Password": "Password",
|
||||
"Station": "DefaultStation",
|
||||
"DtuId": "DefaultDtuId",
|
||||
|
||||
"HeartbeatHexString": "HeartbeatHexString",
|
||||
"EndianType": "EndianType",
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"OperCode": "操作员代码",
|
||||
"Password": "写入密码",
|
||||
"Station": "通讯地址",
|
||||
"DtuId": "默认DtuId",
|
||||
|
||||
"HeartbeatHexString": "心跳验证(HexString)",
|
||||
"EndianType": "解析规则",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<EditorItem @bind-Field=context.Password />
|
||||
<EditorItem @bind-Field=context.ConnectTimeout />
|
||||
<EditorItem @bind-Field=context.Station />
|
||||
<EditorItem @bind-Field=context.DtuId />
|
||||
<EditorItem @bind-Field=context.CheckClearTime />
|
||||
<EditorItem @bind-Field=context.HeartbeatHexString />
|
||||
<EditorItem @bind-Field=context.CacheTimeout />
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"ModbusType": "ProtocolType",
|
||||
"HeartbeatHexString": "HeartbeatHexString",
|
||||
"Station": "DefaultStation",
|
||||
"DtuId": "DefaultDtuId",
|
||||
"EndianType": "EndianType",
|
||||
"IsStringReverseByteWord": "StringReverseByteWord",
|
||||
"CheckClearTime": "CheckClearTime",
|
||||
@@ -46,4 +47,4 @@
|
||||
"DataType": "DataType",
|
||||
"VariableRpcEnable": "VariableRpcEnable"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"ModbusType": "协议类型",
|
||||
"HeartbeatHexString": "心跳验证(HexString)",
|
||||
"Station": "默认站号",
|
||||
"DtuId": "默认DtuId",
|
||||
"EndianType": "解析规则",
|
||||
"IsStringReverseByteWord": "字符串反转",
|
||||
"CheckClearTime": "客户端连接滑动过期时间",
|
||||
@@ -47,4 +48,4 @@
|
||||
"DataType": "数据类型",
|
||||
"VariableRpcEnable": "允许写入"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ public class ModbusMaster : CollectBase
|
||||
_plc = new(channel)
|
||||
{
|
||||
EndianType = _driverPropertys.EndianType,
|
||||
DtuId = _driverPropertys.DtuId,
|
||||
IsStringReverseByteWord = _driverPropertys.IsStringReverseByteWord,
|
||||
SendDelayTime = _driverPropertys.SendDelayTime,
|
||||
CacheTimeout = _driverPropertys.CacheTimeout,
|
||||
|
||||
@@ -35,6 +35,12 @@ public class ModbusMasterProperty : CollectPropertyBase
|
||||
[DynamicProperty]
|
||||
public byte Station { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 默认DtuId
|
||||
/// </summary>
|
||||
[DynamicProperty]
|
||||
public string? DtuId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认解析顺序
|
||||
/// </summary>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<EditorItem @bind-Field=context.ModbusType />
|
||||
<EditorItem @bind-Field=context.ConnectTimeout />
|
||||
<EditorItem @bind-Field=context.Station />
|
||||
<EditorItem @bind-Field=context.DtuId />
|
||||
<EditorItem @bind-Field=context.CheckClearTime />
|
||||
<EditorItem @bind-Field=context.HeartbeatHexString />
|
||||
<EditorItem @bind-Field=context.CacheTimeout />
|
||||
|
||||
Reference in New Issue
Block a user