diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 0c1611566..f8919426e 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,9 +1,9 @@ - 10.11.52 - 10.11.52 - 10.11.52 + 10.11.54 + 10.11.54 + 10.11.54 10.11.5 10.11.4 8.0.20 diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/IChannel.cs b/src/Foundation/ThingsGateway.Foundation/Channel/IChannel.cs index eb41c2ab3..54c135886 100644 --- a/src/Foundation/ThingsGateway.Foundation/Channel/IChannel.cs +++ b/src/Foundation/ThingsGateway.Foundation/Channel/IChannel.cs @@ -57,7 +57,7 @@ public interface IChannel : ISetupConfigObject, IDisposable, IClosableClient, IC /// public ChannelEventHandler Stoping { get; } - void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue); + void ResetSign(int minSign = 1, int maxSign = ushort.MaxValue - 1); } diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/IClientChannel.cs b/src/Foundation/ThingsGateway.Foundation/Channel/IClientChannel.cs index 30249c7c9..6c3eb9251 100644 --- a/src/Foundation/ThingsGateway.Foundation/Channel/IClientChannel.cs +++ b/src/Foundation/ThingsGateway.Foundation/Channel/IClientChannel.cs @@ -30,6 +30,7 @@ public interface IClientChannel : IChannel, ISender, IClient, IClientSender, IOn WaitHandlePool WaitHandlePool { get; } WaitLock GetLock(string key); + void LogSeted(bool logSeted); /// /// 设置数据处理适配器 diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/OtherChannel.cs b/src/Foundation/ThingsGateway.Foundation/Channel/OtherChannel.cs index b267dcf37..ce97d1d68 100644 --- a/src/Foundation/ThingsGateway.Foundation/Channel/OtherChannel.cs +++ b/src/Foundation/ThingsGateway.Foundation/Channel/OtherChannel.cs @@ -36,7 +36,7 @@ public class OtherChannel : SetupConfigObject, IClientChannel public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config; - public void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue) + public void ResetSign(int minSign = 1, int maxSign = ushort.MaxValue - 1) { var pool = WaitHandlePool; WaitHandlePool = new WaitHandlePool(minSign, maxSign); @@ -68,7 +68,7 @@ public class OtherChannel : SetupConfigObject, IClientChannel /// /// 等待池 /// - public WaitHandlePool WaitHandlePool { get; internal set; } = new(0, ushort.MaxValue); + public WaitHandlePool WaitHandlePool { get; internal set; } = new(1, ushort.MaxValue - 1); /// public WaitLock WaitLock => ChannelOptions.WaitLock; @@ -98,7 +98,10 @@ public class OtherChannel : SetupConfigObject, IClientChannel logSet = false; } - + public void LogSeted(bool logSeted) + { + logSet = logSeted; + } /// /// 设置数据处理适配器。 /// diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/SerialPortChannel.cs b/src/Foundation/ThingsGateway.Foundation/Channel/SerialPortChannel.cs index 442f24491..dc43387cb 100644 --- a/src/Foundation/ThingsGateway.Foundation/Channel/SerialPortChannel.cs +++ b/src/Foundation/ThingsGateway.Foundation/Channel/SerialPortChannel.cs @@ -31,7 +31,7 @@ public class SerialPortChannel : SerialPortClient, IClientChannel public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config; - public void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue) + public void ResetSign(int minSign = 1, int maxSign = ushort.MaxValue - 1) { var pool = WaitHandlePool; WaitHandlePool = new WaitHandlePool(minSign, maxSign); @@ -71,6 +71,11 @@ public class SerialPortChannel : SerialPortClient, IClientChannel logSet = false; } + public void LogSeted(bool logSeted) + { + logSet = logSeted; + } + /// public ChannelEventHandler Started { get; } = new(); @@ -86,7 +91,7 @@ public class SerialPortChannel : SerialPortClient, IClientChannel /// /// 等待池 /// - public WaitHandlePool WaitHandlePool { get; internal set; } = new(0, ushort.MaxValue); + public WaitHandlePool WaitHandlePool { get; internal set; } = new(1, ushort.MaxValue - 1); /// public WaitLock WaitLock => ChannelOptions.WaitLock; diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/TcpClientChannel.cs b/src/Foundation/ThingsGateway.Foundation/Channel/TcpClientChannel.cs index 8b7d1be86..46714a102 100644 --- a/src/Foundation/ThingsGateway.Foundation/Channel/TcpClientChannel.cs +++ b/src/Foundation/ThingsGateway.Foundation/Channel/TcpClientChannel.cs @@ -28,7 +28,7 @@ public class TcpClientChannel : TcpClient, IClientChannel ResetSign(); } public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config; - public void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue) + public void ResetSign(int minSign = 1, int maxSign = ushort.MaxValue - 1) { var pool = WaitHandlePool; WaitHandlePool = new WaitHandlePool(minSign, maxSign); @@ -51,6 +51,10 @@ public class TcpClientChannel : TcpClient, IClientChannel logSet = false; } + public void LogSeted(bool logSeted) + { + logSet = logSeted; + } /// public ChannelReceivedEventHandler ChannelReceived { get; } = new(); @@ -79,7 +83,7 @@ public class TcpClientChannel : TcpClient, IClientChannel /// /// 等待池 /// - public WaitHandlePool WaitHandlePool { get; internal set; } = new(0, ushort.MaxValue); + public WaitHandlePool WaitHandlePool { get; internal set; } = new(1, ushort.MaxValue - 1); public virtual WaitLock GetLock(string key) => WaitLock; /// diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/TcpServiceChannel.cs b/src/Foundation/ThingsGateway.Foundation/Channel/TcpServiceChannel.cs index b12d0dcf5..1535a1267 100644 --- a/src/Foundation/ThingsGateway.Foundation/Channel/TcpServiceChannel.cs +++ b/src/Foundation/ThingsGateway.Foundation/Channel/TcpServiceChannel.cs @@ -210,7 +210,7 @@ public class TcpServiceChannel : TcpServiceChannelBase, IChann } public int MinSign { get; private set; } = 0; public int MaxSign { get; private set; } = ushort.MaxValue; - public void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue) + public void ResetSign(int minSign = 1, int maxSign = ushort.MaxValue - 1) { MinSign = minSign; MaxSign = maxSign; diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/TcpSessionClientChannel.cs b/src/Foundation/ThingsGateway.Foundation/Channel/TcpSessionClientChannel.cs index 23da58af8..f44646b67 100644 --- a/src/Foundation/ThingsGateway.Foundation/Channel/TcpSessionClientChannel.cs +++ b/src/Foundation/ThingsGateway.Foundation/Channel/TcpSessionClientChannel.cs @@ -43,8 +43,11 @@ public class TcpSessionClientChannel : TcpSessionClient, IClientChannel logSet = false; } - - public void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue) + public void LogSeted(bool logSeted) + { + logSet = logSeted; + } + public void ResetSign(int minSign = 1, int maxSign = ushort.MaxValue - 1) { var pool = WaitHandlePool; WaitHandlePool = new WaitHandlePool(minSign, maxSign); @@ -79,7 +82,7 @@ public class TcpSessionClientChannel : TcpSessionClient, IClientChannel /// /// 等待池 /// - public WaitHandlePool WaitHandlePool { get; private set; } = new(0, ushort.MaxValue); + public WaitHandlePool WaitHandlePool { get; private set; } = new(1, ushort.MaxValue - 1); /// public WaitLock WaitLock { get; internal set; } = new(nameof(TcpSessionClientChannel)); diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/UdpSessionChannel.cs b/src/Foundation/ThingsGateway.Foundation/Channel/UdpSessionChannel.cs index 19fe66b8b..4bd52d4a1 100644 --- a/src/Foundation/ThingsGateway.Foundation/Channel/UdpSessionChannel.cs +++ b/src/Foundation/ThingsGateway.Foundation/Channel/UdpSessionChannel.cs @@ -40,6 +40,10 @@ public class UdpSessionChannel : UdpSession, IClientChannel handleAdapter.Logger = log; } } + public void LogSeted(bool logSeted) + { + logSet = logSeted; + } /// public void SetDataHandlingAdapter(DataHandlingAdapter adapter) { @@ -50,7 +54,7 @@ public class UdpSessionChannel : UdpSession, IClientChannel } - public void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue) + public void ResetSign(int minSign = 1, int maxSign = ushort.MaxValue - 1) { var pool = WaitHandlePool; WaitHandlePool = new WaitHandlePool(minSign, maxSign); @@ -89,7 +93,7 @@ public class UdpSessionChannel : UdpSession, IClientChannel /// /// 等待池 /// - public WaitHandlePool WaitHandlePool { get; set; } = new(0, ushort.MaxValue); + public WaitHandlePool WaitHandlePool { get; internal set; } = new(1, ushort.MaxValue - 1); /// public WaitLock WaitLock => ChannelOptions.WaitLock; diff --git a/src/Foundation/ThingsGateway.Foundation/Device/DeviceBase.cs b/src/Foundation/ThingsGateway.Foundation/Device/DeviceBase.cs index b59e8880e..7edf877e4 100644 --- a/src/Foundation/ThingsGateway.Foundation/Device/DeviceBase.cs +++ b/src/Foundation/ThingsGateway.Foundation/Device/DeviceBase.cs @@ -569,7 +569,7 @@ public abstract class DeviceBase : AsyncAndSyncDisposableObject, IDevice { timeoutStatus = reusableTimeout.TimeoutStatus; return timeoutStatus - ? new MessageBase(new TimeoutException()) + ? new MessageBase(new TimeoutException()) { ErrorMessage = $"Timeout, sign: {sign}" } : new MessageBase(new OperationCanceledException()); } catch (Exception ex) @@ -583,9 +583,15 @@ public abstract class DeviceBase : AsyncAndSyncDisposableObject, IDevice _reusableTimeouts.Return(reusableTimeout); } - return waitData.Status == WaitDataStatus.Success - ? waitData.CompletedData - : new MessageBase(waitData.Check(timeoutStatus)); + if (waitData.Status == WaitDataStatus.Success) + { + return waitData.CompletedData; + } + else + { + var operResult = waitData.Check(timeoutStatus); + return new MessageBase(operResult) { ErrorMessage = $"{operResult.ErrorMessage}, sign: {sign}" }; + } } catch (Exception ex) { @@ -978,6 +984,7 @@ public abstract class DeviceBase : AsyncAndSyncDisposableObject, IDevice { lock (Channel) { + Channel.Starting.Remove(ChannelStarting); Channel.Stoped.Remove(ChannelStoped); Channel.Started.Remove(ChannelStarted); @@ -1018,6 +1025,11 @@ public abstract class DeviceBase : AsyncAndSyncDisposableObject, IDevice } Channel.Collects.Remove(this); + if (Channel is IClientChannel clientChannel) + { + clientChannel.LogSeted(false); + } + } } _reusableTimeouts?.SafeDispose(); @@ -1070,6 +1082,12 @@ public abstract class DeviceBase : AsyncAndSyncDisposableObject, IDevice } Channel.Collects.Remove(this); + + if (Channel is IClientChannel clientChannel) + { + clientChannel.LogSeted(false); + } + } _reusableTimeouts?.SafeDispose(); diff --git a/src/Foundation/ThingsGateway.Foundation/ThingsGateway.Foundation.csproj b/src/Foundation/ThingsGateway.Foundation/ThingsGateway.Foundation.csproj index 575db1b1d..122e026e7 100644 --- a/src/Foundation/ThingsGateway.Foundation/ThingsGateway.Foundation.csproj +++ b/src/Foundation/ThingsGateway.Foundation/ThingsGateway.Foundation.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Driver/Collect/CollectBase.cs b/src/Gateway/ThingsGateway.Gateway.Application/Driver/Collect/CollectBase.cs index b6c3adbd9..a6c9895b4 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Driver/Collect/CollectBase.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Driver/Collect/CollectBase.cs @@ -482,7 +482,6 @@ public abstract partial class CollectBase : DriverBase protected virtual Task TestOnline(object? state, CancellationToken cancellationToken) { - CurrentDevice.SetDeviceStatus(TimerX.Now, false, null); return Task.CompletedTask; } diff --git a/src/Gateway/ThingsGateway.Gateway.Application/ThingsGateway.Gateway.Application.csproj b/src/Gateway/ThingsGateway.Gateway.Application/ThingsGateway.Gateway.Application.csproj index ad20b0bfa..90710e0c7 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/ThingsGateway.Gateway.Application.csproj +++ b/src/Gateway/ThingsGateway.Gateway.Application/ThingsGateway.Gateway.Application.csproj @@ -11,9 +11,9 @@ - - - + + + diff --git a/src/Plugin/ThingsGateway.Foundation.Benchmark/Benchmark/ModbusBenchmark.cs b/src/Plugin/ThingsGateway.Foundation.Benchmark/Benchmark/ModbusBenchmark.cs index c0529270a..65edf82aa 100644 --- a/src/Plugin/ThingsGateway.Foundation.Benchmark/Benchmark/ModbusBenchmark.cs +++ b/src/Plugin/ThingsGateway.Foundation.Benchmark/Benchmark/ModbusBenchmark.cs @@ -19,7 +19,6 @@ using Longbow.TcpSocket; using Microsoft.Extensions.DependencyInjection; -using System.IO.Pipelines; using System.Net.Sockets; using ThingsGateway.Foundation.Modbus; diff --git a/src/Plugin/ThingsGateway.Foundation.Benchmark/Benchmark/S7Benchmark.cs b/src/Plugin/ThingsGateway.Foundation.Benchmark/Benchmark/S7Benchmark.cs index 83abac66d..74b351927 100644 --- a/src/Plugin/ThingsGateway.Foundation.Benchmark/Benchmark/S7Benchmark.cs +++ b/src/Plugin/ThingsGateway.Foundation.Benchmark/Benchmark/S7Benchmark.cs @@ -17,8 +17,6 @@ using HslCommunication.Profinet.Siemens; using S7.Net; -using System.IO.Pipelines; - using ThingsGateway.Foundation.SiemensS7; using TouchSocket.Core; diff --git a/src/Plugin/ThingsGateway.Foundation.Benchmark/Program.cs b/src/Plugin/ThingsGateway.Foundation.Benchmark/Program.cs index 2effa8d86..dcee747e6 100644 --- a/src/Plugin/ThingsGateway.Foundation.Benchmark/Program.cs +++ b/src/Plugin/ThingsGateway.Foundation.Benchmark/Program.cs @@ -20,9 +20,9 @@ namespace BenchmarkConsoleApp { internal class Program { - public static int ClientCount = 50; - public static int TaskNumberOfItems = 1; - public static int NumberOfItems = 50; + public static int ClientCount = 30; + public static int TaskNumberOfItems = 30; + public static int NumberOfItems = 30; private static async Task Main(string[] args) { diff --git a/src/Plugin/ThingsGateway.Foundation.Benchmark/ThingsGateway.Foundation.Benchmark.csproj b/src/Plugin/ThingsGateway.Foundation.Benchmark/ThingsGateway.Foundation.Benchmark.csproj index a0d988f4b..cdb5c2861 100644 --- a/src/Plugin/ThingsGateway.Foundation.Benchmark/ThingsGateway.Foundation.Benchmark.csproj +++ b/src/Plugin/ThingsGateway.Foundation.Benchmark/ThingsGateway.Foundation.Benchmark.csproj @@ -49,7 +49,7 @@ - + diff --git a/src/Plugin/ThingsGateway.Foundation.Test/ModbusTest.cs b/src/Plugin/ThingsGateway.Foundation.Test/ModbusTest.cs index 85c92c9b1..2b1ffdf6c 100644 --- a/src/Plugin/ThingsGateway.Foundation.Test/ModbusTest.cs +++ b/src/Plugin/ThingsGateway.Foundation.Test/ModbusTest.cs @@ -28,14 +28,14 @@ public class ModbusTest [Theory] - [InlineData("400045", true, "00010000002F01032C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")] - [InlineData("300045", true, "00010000002F01042C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")] - [InlineData("100045", true, "000100000009010206000000000000")] - [InlineData("000045", true, "000100000009010106000000000000")] - [InlineData("400045", false, "0001000000060106002C0001", "1", DataTypeEnum.UInt16)] - [InlineData("000045", false, "0001000000060105002CFF00", "true", DataTypeEnum.Boolean)] - [InlineData("400045;w=16", false, "0001000000090110002C0001020001", "1", DataTypeEnum.UInt16)] - [InlineData("000045;w=15", false, "000100000008010F002C00010101", "true", DataTypeEnum.Boolean)] + [InlineData("400045", true, "00020000002F01032C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")] + [InlineData("300045", true, "00020000002F01042C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")] + [InlineData("100045", true, "000200000009010206000000000000")] + [InlineData("000045", true, "000200000009010106000000000000")] + [InlineData("400045", false, "0002000000060106002C0001", "1", DataTypeEnum.UInt16)] + [InlineData("000045", false, "0002000000060105002CFF00", "true", DataTypeEnum.Boolean)] + [InlineData("400045;w=16", false, "0002000000090110002C0001020001", "1", DataTypeEnum.UInt16)] + [InlineData("000045;w=15", false, "000200000008010F002C00010101", "true", DataTypeEnum.Boolean)] public async Task ModbusTcp_ReadWrite_OK(string address, bool read, string data, string writeData = null, DataTypeEnum dataTypeEnum = DataTypeEnum.UInt16) { var modbusChannel = new TouchSocketConfig().GetChannel(new ChannelOptions() diff --git a/src/Plugin/ThingsGateway.Foundation.Test/SiemensS7Test.cs b/src/Plugin/ThingsGateway.Foundation.Test/SiemensS7Test.cs index e4c4eb9e3..daea76d37 100644 --- a/src/Plugin/ThingsGateway.Foundation.Test/SiemensS7Test.cs +++ b/src/Plugin/ThingsGateway.Foundation.Test/SiemensS7Test.cs @@ -29,8 +29,8 @@ public class SiemensS7Test [Theory] - [InlineData("M100", true, "03 00 00 1B 02 F0 80 32 03 00 00 00 01 00 02 00 06 00 00 04 01 FF 04 00 10 00 00")] - [InlineData("M100", false, "03 00 00 16 02 F0 80 32 03 00 00 00 01 00 02 00 01 00 00 05 01 FF", "1", DataTypeEnum.UInt16)] + [InlineData("M100", true, "03 00 00 1B 02 F0 80 32 03 00 00 00 02 00 02 00 06 00 00 04 01 FF 04 00 10 00 00")] + [InlineData("M100", false, "03 00 00 16 02 F0 80 32 03 00 00 00 02 00 02 00 01 00 00 05 01 FF", "1", DataTypeEnum.UInt16)] public async Task SiemensS7_ReadWrite_OK(string address, bool read, string data, string writeData = null, DataTypeEnum dataTypeEnum = DataTypeEnum.UInt16) { var siemensS7Channel = new TouchSocketConfig().GetChannel(new ChannelOptions()