diff --git a/Modbus.Net/ModBus.Net/BaseConnector.cs b/Modbus.Net/ModBus.Net/BaseConnector.cs index a6f97f6..4f24c16 100644 --- a/Modbus.Net/ModBus.Net/BaseConnector.cs +++ b/Modbus.Net/ModBus.Net/BaseConnector.cs @@ -15,6 +15,11 @@ namespace ModBus.Net /// public abstract bool Connect(); /// + /// 连接PLC,异步 + /// + /// /// + public abstract Task ConnectAsync(); + /// /// 断开PLC /// /// @@ -26,10 +31,22 @@ namespace ModBus.Net /// public abstract bool SendMsgWithoutReturn(byte[] message); /// + /// 无返回发送数据,异步 + /// + /// + /// + public abstract Task SendMsgWithoutReturnAsync(byte[] message); + /// /// 带返回发送数据 /// /// /// public abstract byte[] SendMsg(byte[] message); + /// + /// 带返回发送数据,异步 + /// + /// + /// + public abstract Task SendMsgAsync(byte[] message); } } diff --git a/Modbus.Net/ModBus.Net/BaseProtocal.cs b/Modbus.Net/ModBus.Net/BaseProtocal.cs index 407a9ab..9e41617 100644 --- a/Modbus.Net/ModBus.Net/BaseProtocal.cs +++ b/Modbus.Net/ModBus.Net/BaseProtocal.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Threading.Tasks; namespace ModBus.Net { diff --git a/Modbus.Net/ModBus.Net/ComConnector.cs b/Modbus.Net/ModBus.Net/ComConnector.cs index e7dfe30..b8fec78 100644 --- a/Modbus.Net/ModBus.Net/ComConnector.cs +++ b/Modbus.Net/ModBus.Net/ComConnector.cs @@ -52,6 +52,11 @@ namespace ModBus.Net return false; } + public override Task ConnectAsync() + { + return Task.FromResult(Connect()); + } + public override bool Disconnect() { if (serialPort1 != null) @@ -77,6 +82,11 @@ namespace ModBus.Net } + public override Task SendMsgWithoutReturnAsync(byte[] message) + { + return Task.FromResult(SendMsgWithoutReturn(message)); + } + public override byte[] SendMsg(byte[] sendbytes) { try @@ -95,6 +105,11 @@ namespace ModBus.Net } } + public override Task SendMsgAsync(byte[] message) + { + return Task.FromResult(SendMsg(message)); + } + public override bool SendMsgWithoutReturn(byte[] sendbytes) { try diff --git a/Modbus.Net/ModBus.Net/ModBus.Net.csproj b/Modbus.Net/ModBus.Net/ModBus.Net.csproj index 290f210..9dd7969 100644 --- a/Modbus.Net/ModBus.Net/ModBus.Net.csproj +++ b/Modbus.Net/ModBus.Net/ModBus.Net.csproj @@ -30,6 +30,12 @@ prompt 4 + + true + + + key.pfx + @@ -42,6 +48,7 @@ + @@ -82,6 +89,9 @@ ConfigurationManager.Designer.cs + + +