diff --git a/Modbus.Net/Modbus.Net/Machine/AddressCombiner.cs b/Modbus.Net/Modbus.Net/Machine/AddressCombiner.cs
index 48558a7..849d7d5 100644
--- a/Modbus.Net/Modbus.Net/Machine/AddressCombiner.cs
+++ b/Modbus.Net/Modbus.Net/Machine/AddressCombiner.cs
@@ -1,4 +1,5 @@
-using System;
+using Quartz.Util;
+using System;
using System.Collections.Generic;
using System.Linq;
@@ -158,17 +159,29 @@ namespace Modbus.Net
OriginalAddresses = originalAddresses.ToList()
});
}
+ var newAns = MaxExclude(ans);
+ return newAns;
+ }
+
+ ///
+ /// 将单个超长连续地址池拆分
+ ///
+ /// 拆分前的连续地址池
+ /// 拆分后的连续地址池
+ protected List> MaxExclude(List> ans)
+ {
var newAns = new List>();
foreach (var communicationUnit in ans)
{
var oldByteCount = communicationUnit.GetCount *
BigEndianValueHelper.Instance.ByteLength[communicationUnit.DataType.FullName];
+ var oldOriginalAddresses = communicationUnit.OriginalAddresses.ToList();
while (oldByteCount * BigEndianValueHelper.Instance.ByteLength[communicationUnit.DataType.FullName] >
MaxLength)
{
var newOriginalAddresses = new List>();
- var oldOriginalAddresses = communicationUnit.OriginalAddresses.ToList();
var newByteCount = 0.0;
+ var newAddressUnitStart = oldOriginalAddresses.First();
do
{
var currentAddressUnit = oldOriginalAddresses.First();
@@ -180,10 +193,10 @@ namespace Modbus.Net
} while (newByteCount < MaxLength);
var newCommunicationUnit = new CommunicationUnit
{
- Area = communicationUnit.Area,
- Address = communicationUnit.Address,
- SubAddress = communicationUnit.SubAddress,
- DataType = communicationUnit.DataType,
+ Area = newAddressUnitStart.Area,
+ Address = newAddressUnitStart.Address,
+ SubAddress = newAddressUnitStart.SubAddress,
+ DataType = typeof(byte),
GetCount =
(int)
Math.Ceiling(newByteCount /
@@ -193,10 +206,17 @@ namespace Modbus.Net
newAns.Add(newCommunicationUnit);
}
+ var addressUnitStart = oldOriginalAddresses.First();
+ communicationUnit.Area = addressUnitStart.Area;
+ communicationUnit.Address = addressUnitStart.Address;
+ communicationUnit.SubAddress = addressUnitStart.SubAddress;
+ communicationUnit.Address = addressUnitStart.Address;
+ communicationUnit.DataType = typeof(byte);
communicationUnit.GetCount =
(int)
Math.Ceiling(oldByteCount /
BigEndianValueHelper.Instance.ByteLength[communicationUnit.DataType.FullName]);
+ communicationUnit.OriginalAddresses = oldOriginalAddresses;
newAns.Add(communicationUnit);
}
return newAns;