mirror of
https://github.com/ThingsGateway/ThingsGateway.git
synced 2026-10-23 17:12:15 +08:00
更新touchsocket版本,更新2.1.0.3
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<Version>2.1.0.2</Version>
|
||||
<Version>2.1.0.3</Version>
|
||||
<Authors>Diego</Authors>
|
||||
<Product>ThingsGateway</Product>
|
||||
<Copyright>© 2023-present Diego</Copyright>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<PackageReference Include="Masa.Blazor" Version="1.0.2" />
|
||||
<PackageReference Include="Masa.Blazor" Version="1.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.10" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
@@ -82,7 +82,7 @@ public partial class TcpClientPage
|
||||
var LogMessage = new TouchSocket.Core.LoggerGroup() { LogLevel = TouchSocket.Core.LogLevel.Trace };
|
||||
LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = TouchSocket.Core.LogLevel.Trace });
|
||||
config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage));
|
||||
config.SetRemoteIPHost(new IPHost(IP + ":" + Port)).SetBufferLength(300);
|
||||
config.SetRemoteIPHost(new IPHost(IP + ":" + Port));
|
||||
//载入配置
|
||||
TcpClientEx.Setup(config);
|
||||
return TcpClientEx;
|
||||
@@ -96,7 +96,7 @@ public partial class TcpClientPage
|
||||
var LogMessage = new TouchSocket.Core.LoggerGroup() { LogLevel = TouchSocket.Core.LogLevel.Trace };
|
||||
LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = TouchSocket.Core.LogLevel.Trace });
|
||||
config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage));
|
||||
config.SetRemoteIPHost(new IPHost(IP + ":" + Port)).SetBufferLength(300);
|
||||
config.SetRemoteIPHost(new IPHost(IP + ":" + Port));
|
||||
TcpClientEx = new TcpClientEx();
|
||||
TcpClientEx.Setup(config);
|
||||
base.OnInitialized();
|
||||
|
||||
@@ -72,7 +72,6 @@ public partial class TcpServerPage
|
||||
LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = TouchSocket.Core.LogLevel.Trace });
|
||||
config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage));
|
||||
config.SetListenIPHosts(new IPHost[] { new IPHost(ip + ":" + port) });
|
||||
config.SetBufferLength(300);
|
||||
//载入配置
|
||||
TcpServer.Setup(config);
|
||||
return TcpServer;
|
||||
@@ -88,7 +87,6 @@ public partial class TcpServerPage
|
||||
LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = TouchSocket.Core.LogLevel.Trace });
|
||||
config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage));
|
||||
config.SetListenIPHosts(new IPHost[] { new IPHost(ip + ":" + port) });
|
||||
config.SetBufferLength(300);
|
||||
TcpServer = new TcpService();
|
||||
TcpServer.Setup(config);
|
||||
base.OnInitialized();
|
||||
|
||||
@@ -71,7 +71,7 @@ public partial class UdpSessionPage : IDisposable
|
||||
var LogMessage = new TouchSocket.Core.LoggerGroup() { LogLevel = TouchSocket.Core.LogLevel.Trace };
|
||||
LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = TouchSocket.Core.LogLevel.Trace });
|
||||
config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage));
|
||||
config.SetRemoteIPHost(new IPHost(ip + ":" + port)).SetBufferLength(300);
|
||||
config.SetRemoteIPHost(new IPHost(ip + ":" + port));
|
||||
config.SetBindIPHost(new IPHost(0));
|
||||
//载入配置
|
||||
UdpSession.Setup(config);
|
||||
@@ -88,7 +88,7 @@ public partial class UdpSessionPage : IDisposable
|
||||
var LogMessage = new TouchSocket.Core.LoggerGroup() { LogLevel = TouchSocket.Core.LogLevel.Trace };
|
||||
LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = TouchSocket.Core.LogLevel.Trace });
|
||||
config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage));
|
||||
config.SetRemoteIPHost(new IPHost(ip + ":" + port)).SetBufferLength(300);
|
||||
config.SetRemoteIPHost(new IPHost(ip + ":" + port));
|
||||
config.SetBindIPHost(new IPHost(0));
|
||||
UdpSession = new UdpSession();
|
||||
UdpSession.Setup(config);
|
||||
|
||||
@@ -64,13 +64,25 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
public TcpClientBaseEx()
|
||||
{
|
||||
this.Protocol = Protocol.Tcp;
|
||||
this.m_receiveCounter = new ValueCounter
|
||||
{
|
||||
Period = TimeSpan.FromSeconds(1),
|
||||
OnPeriod = this.OnReceivePeriod
|
||||
};
|
||||
this.m_sendCounter = new ValueCounter
|
||||
{
|
||||
Period = TimeSpan.FromSeconds(1),
|
||||
OnPeriod = this.OnSendPeriod
|
||||
};
|
||||
}
|
||||
|
||||
#region 变量
|
||||
private DelaySender m_delaySender;
|
||||
private Stream m_workStream;
|
||||
private int m_bufferRate = 1;
|
||||
private long m_bufferRate = 1;
|
||||
private volatile bool m_online;
|
||||
ValueCounter m_receiveCounter;
|
||||
ValueCounter m_sendCounter;
|
||||
#endregion 变量
|
||||
|
||||
#region 事件
|
||||
@@ -115,8 +127,6 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
|
||||
private void PrivateOnConnecting(ConnectingEventArgs e)
|
||||
{
|
||||
this.LastReceivedTime = DateTime.Now;
|
||||
this.LastSendTime = DateTime.Now;
|
||||
if (this.CanSetDataHandlingAdapter)
|
||||
{
|
||||
this.SetDataHandlingAdapter(this.Config.GetValue(TouchSocketConfigExtension.TcpDataHandlingAdapterProperty).Invoke());
|
||||
@@ -206,10 +216,10 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
#region 属性
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime LastReceivedTime { get; private set; }
|
||||
public DateTime LastReceivedTime => this.m_receiveCounter.LastIncrement;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime LastSendTime { get; private set; }
|
||||
public DateTime LastSendTime => this.m_sendCounter.LastIncrement;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Func<ByteBlock, bool> OnHandleRawBuffer { get; set; }
|
||||
@@ -520,6 +530,44 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
return this.m_workStream;
|
||||
}
|
||||
|
||||
private void OnReceivePeriod(long value)
|
||||
{
|
||||
this.ReceiveBufferSize = TouchSocketUtility.HitBufferLength(value);
|
||||
}
|
||||
|
||||
private void OnSendPeriod(long value)
|
||||
{
|
||||
this.SendBufferSize = TouchSocketUtility.HitBufferLength(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int ReceiveBufferSize
|
||||
{
|
||||
get => base.ReceiveBufferSize;
|
||||
set
|
||||
{
|
||||
base.ReceiveBufferSize = value;
|
||||
if (this.MainSocket != null)
|
||||
{
|
||||
this.MainSocket.ReceiveBufferSize = base.ReceiveBufferSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int SendBufferSize
|
||||
{
|
||||
get => base.SendBufferSize;
|
||||
set
|
||||
{
|
||||
base.SendBufferSize = value;
|
||||
if (this.MainSocket != null)
|
||||
{
|
||||
this.MainSocket.SendBufferSize = base.SendBufferSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void SetDataHandlingAdapter(SingleStreamDataHandlingAdapter adapter)
|
||||
{
|
||||
@@ -655,10 +703,6 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
protected virtual void LoadConfig(TouchSocketConfig config)
|
||||
{
|
||||
this.RemoteIPHost = config.GetValue(TouchSocketConfigExtension.RemoteIPHostProperty);
|
||||
if (config.GetValue(TouchSocketConfigExtension.BufferLengthProperty) is int value)
|
||||
{
|
||||
this.SetBufferLength(value);
|
||||
}
|
||||
this.Logger ??= this.Container.Resolve<ILog>();
|
||||
this.ReceiveType = config.GetValue(TouchSocketConfigExtension.ReceiveTypeProperty);
|
||||
}
|
||||
@@ -727,7 +771,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
var eventArgs = new SocketAsyncEventArgs();
|
||||
eventArgs.Completed += this.EventArgs_Completed;
|
||||
|
||||
var byteBlock = BytePool.Default.GetByteBlock(this.BufferLength);
|
||||
var byteBlock = BytePool.Default.GetByteBlock(this.ReceiveBufferSize);
|
||||
eventArgs.UserToken = byteBlock;
|
||||
eventArgs.SetBuffer(byteBlock.Buffer, 0, byteBlock.Capacity);
|
||||
if (!this.MainSocket.ReceiveAsync(eventArgs))
|
||||
@@ -750,7 +794,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var byteBlock = new ByteBlock(this.BufferLength);
|
||||
var byteBlock = new ByteBlock(this.ReceiveBufferSize);
|
||||
try
|
||||
{
|
||||
var r = this.MainSocket.Receive(byteBlock.Buffer);
|
||||
@@ -773,7 +817,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
|
||||
private void BeginSsl()
|
||||
{
|
||||
var byteBlock = new ByteBlock(this.BufferLength);
|
||||
var byteBlock = new ByteBlock(this.ReceiveBufferSize);
|
||||
try
|
||||
{
|
||||
this.m_workStream.BeginRead(byteBlock.Buffer, 0, byteBlock.Capacity, this.EndSsl, byteBlock);
|
||||
@@ -813,8 +857,6 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
socket = new Socket(SocketType.Stream, ProtocolType.Tcp)
|
||||
{
|
||||
ReceiveBufferSize = this.BufferLength,
|
||||
SendBufferSize = this.BufferLength,
|
||||
SendTimeout = this.Config.GetValue(TouchSocketConfigExtension.SendTimeoutProperty)
|
||||
};
|
||||
}
|
||||
@@ -822,8 +864,6 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
socket = new Socket(iPHost.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
|
||||
{
|
||||
ReceiveBufferSize = this.BufferLength,
|
||||
SendBufferSize = this.BufferLength,
|
||||
SendTimeout = this.Config.GetValue(TouchSocketConfigExtension.SendTimeoutProperty)
|
||||
};
|
||||
}
|
||||
@@ -831,8 +871,8 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
#if NET45_OR_GREATER
|
||||
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
|
||||
socket.IOControl(IOControlCode.KeepAliveValues, keepAliveValue.KeepAliveTime, null);
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
|
||||
socket.IOControl(IOControlCode.KeepAliveValues, keepAliveValue.KeepAliveTime, null);
|
||||
#else
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
@@ -880,7 +920,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
try
|
||||
{
|
||||
this.LastReceivedTime = DateTime.Now;
|
||||
this.m_receiveCounter.Increment(byteBlock.Length);
|
||||
if (this.OnHandleRawBuffer?.Invoke(byteBlock) == false)
|
||||
{
|
||||
return;
|
||||
@@ -1075,8 +1115,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
this.MainSocket.AbsoluteSend(buffer, offset, length);
|
||||
}
|
||||
}
|
||||
|
||||
this.LastSendTime = DateTime.Now;
|
||||
this.m_sendCounter.Increment(length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1138,7 +1177,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
this.HandleBuffer(byteBlock);
|
||||
try
|
||||
{
|
||||
var newByteBlock = BytePool.Default.GetByteBlock(Math.Min(this.BufferLength * this.m_bufferRate, 1024 * 1024));
|
||||
var newByteBlock = BytePool.Default.GetByteBlock((int)Math.Min(this.ReceiveBufferSize * this.m_bufferRate, TouchSocketUtility.MaxBufferLength));
|
||||
e.UserToken = newByteBlock;
|
||||
e.SetBuffer(newByteBlock.Buffer, 0, newByteBlock.Capacity);
|
||||
|
||||
|
||||
@@ -18,21 +18,18 @@ namespace ThingsGateway.Foundation.Serial;
|
||||
public interface ISerial : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据交互缓存池限制
|
||||
/// 发送缓存区大小。最小值=1024。
|
||||
/// </summary>
|
||||
int BufferLength { get; }
|
||||
int SendBufferSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 接收缓存区大小。最小值=1024。
|
||||
/// </summary>
|
||||
int ReceiveBufferSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 日志记录器
|
||||
/// </summary>
|
||||
ILog Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置数据交互缓存池尺寸,min=1024 byte。
|
||||
/// 一般情况下该值用于三个方面,包括:发送、接收缓存,及内存池的默认申请。
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
int SetBufferLength(int value);
|
||||
ILog Logger { get; set; }
|
||||
|
||||
}
|
||||
@@ -20,39 +20,22 @@ public abstract class BaseSerial : DependencyObject, ISerial
|
||||
/// <summary>
|
||||
/// 同步根。
|
||||
/// </summary>
|
||||
protected readonly object SyncRoot;
|
||||
protected readonly object SyncRoot = new object();
|
||||
private int m_receiveBufferSize = 1024 * 64;
|
||||
private int m_sendBufferSize = 1024 * 64;
|
||||
|
||||
/// <summary>
|
||||
/// 通讯基类
|
||||
/// </summary>
|
||||
public BaseSerial()
|
||||
/// <inheritdoc/>
|
||||
public virtual int SendBufferSize
|
||||
{
|
||||
this.SyncRoot = new object();
|
||||
get => m_sendBufferSize;
|
||||
set => m_sendBufferSize = value < 1024 ? 1024 : value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据交互缓存池限制,min=1024 byte
|
||||
/// </summary>
|
||||
public int BufferLength { get; private set; } = 64 * 1024;
|
||||
|
||||
/// <summary>
|
||||
/// 日志记录器
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public virtual int ReceiveBufferSize
|
||||
{
|
||||
get => m_receiveBufferSize;
|
||||
set => m_receiveBufferSize = value < 1024 ? 1024 : value;
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public ILog Logger { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置数据交互缓存池尺寸,min=1024 byte。
|
||||
/// 一般情况下该值用于三个方面,包括:socket的发送、接收缓存,及内存池的默认申请。
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public virtual int SetBufferLength(int value)
|
||||
{
|
||||
if (value < 1024)
|
||||
{
|
||||
value = 1024;
|
||||
}
|
||||
this.BufferLength = value;
|
||||
return this.BufferLength;
|
||||
}
|
||||
}
|
||||
@@ -60,12 +60,27 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
public SerialSessionBase()
|
||||
{
|
||||
this.Protocol = SerialPort;
|
||||
this.m_receiveCounter = new ValueCounter
|
||||
{
|
||||
Period = TimeSpan.FromSeconds(1),
|
||||
OnPeriod = this.OnReceivePeriod
|
||||
};
|
||||
this.m_sendCounter = new ValueCounter
|
||||
{
|
||||
Period = TimeSpan.FromSeconds(1),
|
||||
OnPeriod = this.OnSendPeriod
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#region 变量
|
||||
|
||||
private SerialDelaySender m_delaySender;
|
||||
private int m_bufferRate = 1;
|
||||
private long m_bufferRate = 1;
|
||||
private volatile bool m_online;
|
||||
ValueCounter m_receiveCounter;
|
||||
ValueCounter m_sendCounter;
|
||||
|
||||
#endregion 变量
|
||||
|
||||
#region 事件
|
||||
@@ -110,8 +125,6 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
|
||||
private void PrivateOnConnecting(SerialConnectingEventArgs e)
|
||||
{
|
||||
this.LastReceivedTime = DateTime.Now;
|
||||
this.LastSendTime = DateTime.Now;
|
||||
if (this.CanSetDataHandlingAdapter)
|
||||
{
|
||||
this.SetDataHandlingAdapter(this.Config.GetValue(TouchSocketConfigExtension.TcpDataHandlingAdapterProperty).Invoke());
|
||||
@@ -201,10 +214,10 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
#region 属性
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime LastReceivedTime { get; private set; }
|
||||
public DateTime LastReceivedTime => this.m_receiveCounter.LastIncrement;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime LastSendTime { get; private set; }
|
||||
public DateTime LastSendTime => this.m_sendCounter.LastIncrement;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Func<ByteBlock, bool> OnHandleRawBuffer { get; set; }
|
||||
@@ -370,7 +383,43 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void OnReceivePeriod(long value)
|
||||
{
|
||||
this.ReceiveBufferSize = TouchSocketUtility.HitBufferLength(value);
|
||||
}
|
||||
|
||||
private void OnSendPeriod(long value)
|
||||
{
|
||||
this.SendBufferSize = TouchSocketUtility.HitBufferLength(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int ReceiveBufferSize
|
||||
{
|
||||
get => base.ReceiveBufferSize;
|
||||
set
|
||||
{
|
||||
base.ReceiveBufferSize = value;
|
||||
if (this.MainSerialPort != null && !MainSerialPort.IsOpen)
|
||||
{
|
||||
this.MainSerialPort.ReadBufferSize = base.ReceiveBufferSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int SendBufferSize
|
||||
{
|
||||
get => base.SendBufferSize;
|
||||
set
|
||||
{
|
||||
base.SendBufferSize = value;
|
||||
if (this.MainSerialPort != null && !MainSerialPort.IsOpen)
|
||||
{
|
||||
this.MainSerialPort.WriteBufferSize = base.SendBufferSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void SetDataHandlingAdapter(SingleStreamDataHandlingAdapter adapter)
|
||||
@@ -499,10 +548,6 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
protected virtual void LoadConfig(TouchSocketConfig config)
|
||||
{
|
||||
this.SerialProperty = config.GetValue(SerialConfigExtension.SerialProperty);
|
||||
if (config.GetValue(TouchSocketConfigExtension.BufferLengthProperty) is int value)
|
||||
{
|
||||
this.SetBufferLength(value);
|
||||
}
|
||||
this.Logger ??= this.Container.Resolve<ILog>();
|
||||
this.ReceiveType = config.GetValue(TouchSocketConfigExtension.ReceiveTypeProperty);
|
||||
}
|
||||
@@ -546,7 +591,7 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
if (this.ReceiveType == ReceiveType.Iocp)
|
||||
{
|
||||
SerialReceivedEventArgs eventArgs = new();
|
||||
var byteBlock = BytePool.Default.GetByteBlock(this.BufferLength);
|
||||
var byteBlock = BytePool.Default.GetByteBlock(this.ReceiveBufferSize);
|
||||
byteBlock.SetLength(0);
|
||||
eventArgs.UserToken = byteBlock;
|
||||
if (this.MainSerialPort.BytesToRead > 0)
|
||||
@@ -580,7 +625,7 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
{
|
||||
this.m_bufferRate = 1;
|
||||
SerialReceivedEventArgs eventArgs = new();
|
||||
var newByteBlock = BytePool.Default.GetByteBlock(Math.Min(this.BufferLength * this.m_bufferRate, 1024 * 1024));
|
||||
var newByteBlock = BytePool.Default.GetByteBlock((int)Math.Min(this.ReceiveBufferSize * this.m_bufferRate, TouchSocketUtility.MaxBufferLength));
|
||||
newByteBlock.SetLength(0);
|
||||
eventArgs.UserToken = newByteBlock;
|
||||
if (MainSerialPort.BytesToRead > 0)
|
||||
@@ -597,7 +642,7 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var byteBlock = new ByteBlock(this.BufferLength);
|
||||
var byteBlock = BytePool.Default.GetByteBlock(this.ReceiveBufferSize);
|
||||
try
|
||||
{
|
||||
int r = MainSerialPort.Read(byteBlock.Buffer, 0, MainSerialPort.BytesToRead);
|
||||
@@ -634,7 +679,7 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
this.HandleBuffer(byteBlock);
|
||||
try
|
||||
{
|
||||
var newByteBlock = BytePool.Default.GetByteBlock(Math.Min(this.BufferLength * this.m_bufferRate, 1024 * 1024));
|
||||
var newByteBlock = BytePool.Default.GetByteBlock((int)Math.Min(this.ReceiveBufferSize * this.m_bufferRate, TouchSocketUtility.MaxBufferLength));
|
||||
newByteBlock.SetLength(num);
|
||||
e.UserToken = newByteBlock;
|
||||
|
||||
@@ -678,7 +723,7 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
{
|
||||
try
|
||||
{
|
||||
this.LastReceivedTime = DateTime.Now;
|
||||
this.m_receiveCounter.Increment(byteBlock.Length);
|
||||
if (this.OnHandleRawBuffer?.Invoke(byteBlock) == false)
|
||||
{
|
||||
return;
|
||||
@@ -867,7 +912,7 @@ public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
this.MainSerialPort.AbsoluteSend(buffer, offset, length);
|
||||
}
|
||||
|
||||
this.LastSendTime = DateTime.Now;
|
||||
this.m_sendCounter.Increment(length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="TouchSocket" Version="2.0.0-beta.154" />
|
||||
<PackageReference Include="TouchSocket" Version="2.0.0-beta.156" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)'!='net45'">
|
||||
<PackageReference Include="System.IO.Ports" Version="7.0.0" />
|
||||
|
||||
@@ -837,6 +837,12 @@
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.GetStream">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.TcpClientBaseEx.ReceiveBufferSize">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.TcpClientBaseEx.SendBufferSize">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SetDataHandlingAdapter(TouchSocket.Core.SingleStreamDataHandlingAdapter)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
@@ -1820,9 +1826,14 @@
|
||||
串口基接口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerial.BufferLength">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerial.SendBufferSize">
|
||||
<summary>
|
||||
数据交互缓存池限制
|
||||
发送缓存区大小。最小值=1024。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerial.ReceiveBufferSize">
|
||||
<summary>
|
||||
接收缓存区大小。最小值=1024。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerial.Logger">
|
||||
@@ -1830,14 +1841,6 @@
|
||||
日志记录器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerial.SetBufferLength(System.Int32)">
|
||||
<summary>
|
||||
设置数据交互缓存池尺寸,min=1024 byte。
|
||||
一般情况下该值用于三个方面,包括:发送、接收缓存,及内存池的默认申请。
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.ISerialSession">
|
||||
<summary>
|
||||
<inheritdoc cref="T:ThingsGateway.Foundation.Serial.ISerialSessionBase"/>
|
||||
@@ -1936,28 +1939,14 @@
|
||||
同步根。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.BaseSerial.#ctor">
|
||||
<summary>
|
||||
通讯基类
|
||||
</summary>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.BaseSerial.SendBufferSize">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.BaseSerial.BufferLength">
|
||||
<summary>
|
||||
数据交互缓存池限制,min=1024 byte
|
||||
</summary>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.BaseSerial.ReceiveBufferSize">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.BaseSerial.Logger">
|
||||
<summary>
|
||||
日志记录器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.BaseSerial.SetBufferLength(System.Int32)">
|
||||
<summary>
|
||||
设置数据交互缓存池尺寸,min=1024 byte。
|
||||
一般情况下该值用于三个方面,包括:socket的发送、接收缓存,及内存池的默认申请。
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.SerialDelaySender">
|
||||
<summary>
|
||||
@@ -2157,6 +2146,12 @@
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.ConnectAsync">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.ReceiveBufferSize">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.SendBufferSize">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.SetDataHandlingAdapter(TouchSocket.Core.SingleStreamDataHandlingAdapter)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace DLT645Test
|
||||
.SetSerialProperty(new SerialProperty() //串口链路才需要
|
||||
{
|
||||
PortName = "COM1"
|
||||
}).SetBufferLength(1024);
|
||||
});
|
||||
|
||||
var serialSession = new SerialsSession();//链路对象
|
||||
serialSession.Setup(config);
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace ModbusDemo
|
||||
.SetSerialProperty(new SerialProperty() //串口链路才需要
|
||||
{
|
||||
PortName = "COM1"
|
||||
}).SetBufferLength(1024);
|
||||
});
|
||||
|
||||
var tcpClient1 = new TcpClientEx();//链路对象
|
||||
var tcpClient2 = new TcpClientEx();//链路对象
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<Version>2.1.0.2</Version>
|
||||
<Version>2.1.0.3</Version>
|
||||
<Authors>Diego</Authors>
|
||||
<Product>ThingsGateway</Product>
|
||||
<Copyright>© 2023-present Diego</Copyright>
|
||||
|
||||
@@ -94,7 +94,7 @@ public class DLT645_2007 : CollectBase
|
||||
Parity = driverPropertys.Parity,
|
||||
StopBits = driverPropertys.StopBits,
|
||||
})
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new SerialsSession();
|
||||
((SerialsSession)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ public class DLT645_2007OverTcp : CollectBase
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class ModbusRtu : CollectBase
|
||||
Parity = driverPropertys.Parity,
|
||||
StopBits = driverPropertys.StopBits,
|
||||
})
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new SerialsSession();
|
||||
((SerialsSession)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ public class ModbusRtuOverTcp : CollectBase
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ public class ModbusRtuOverUdp : CollectBase
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBindIPHost(new IPHost(0))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
|
||||
client = new UdpSession();
|
||||
((UdpSession)client).Setup(FoundataionConfig);
|
||||
|
||||
@@ -122,7 +122,7 @@ public class ModbusServer : UpLoadBase
|
||||
{
|
||||
iPHost = new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}");
|
||||
}
|
||||
FoundataionConfig.SetListenIPHosts(new IPHost[] { iPHost }).SetBufferLength(1024);
|
||||
FoundataionConfig.SetListenIPHosts(new IPHost[] { iPHost });
|
||||
var service = new TcpService();
|
||||
service.Setup(FoundataionConfig);
|
||||
//载入配置
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ModbusTcp : CollectBase
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ModbusUdp : CollectBase
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBindIPHost(new IPHost(0))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new UdpSession();
|
||||
((UdpSession)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ThingsGateway.Siemens
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace ThingsGateway.Siemens
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace ThingsGateway.Siemens
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace ThingsGateway.Siemens
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace ThingsGateway.Siemens
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace ThingsGateway.Siemens
|
||||
if (client == null)
|
||||
{
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{driverPropertys.IP}:{driverPropertys.Port}"))
|
||||
.SetBufferLength(1024);
|
||||
;
|
||||
client = new TcpClientEx();
|
||||
((TcpClientEx)client).Setup(FoundataionConfig);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user