From 0707c190865f603614efde24c8c3050805494726 Mon Sep 17 00:00:00 2001 From: Evan Hein Date: Fri, 10 Aug 2018 11:50:31 -0500 Subject: [PATCH 1/2] For .NET Core, TcpClient doesn't support the .Connect() API; only .ConnectAsync(). This requires that our .Connect() wrapper wait for the .ConnectAsync() call to complete before calling .GetStream(), so we will make the .Connect() method awaitable. --- EasyModbusTCPCore/ModbusClient.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/EasyModbusTCPCore/ModbusClient.cs b/EasyModbusTCPCore/ModbusClient.cs index 0a13e5a..29d28f7 100644 --- a/EasyModbusTCPCore/ModbusClient.cs +++ b/EasyModbusTCPCore/ModbusClient.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Text; using System.Collections.Generic; +using System.Threading.Tasks; namespace EasyModbus { @@ -73,13 +74,13 @@ public ModbusClient() /// /// Establish connection to Master device in case of Modbus TCP. Opens COM-Port in case of Modbus RTU /// - public void Connect() + public async Task Connect() { if (debug) StoreLogData.Instance.Store("Open TCP-Socket, IP-Address: " + ipAddress + ", Port: " + port, System.DateTime.Now); tcpClient = new TcpClient(); - var result = tcpClient.ConnectAsync(ipAddress, port); + await tcpClient.ConnectAsync(ipAddress, port); //tcpClient = new TcpClient(ipAddress, port); @@ -91,13 +92,13 @@ public void Connect() /// /// Establish connection to Master device in case of Modbus TCP. /// - public void Connect(string ipAddress, int port) + public async Task Connect(string ipAddress, int port) { if (debug) StoreLogData.Instance.Store("Open TCP-Socket, IP-Address: " + ipAddress + ", Port: " + port, System.DateTime.Now); tcpClient = new TcpClient(); - var result = tcpClient.ConnectAsync(ipAddress, port); + await tcpClient.ConnectAsync(ipAddress, port); //tcpClient = new TcpClient(ipAddress, port); From 9c632594291abd340d70d55cfd8e08eeef93aa84 Mon Sep 17 00:00:00 2001 From: Evan Hein Date: Fri, 10 Aug 2018 11:56:47 -0500 Subject: [PATCH 2/2] EasyModbusTCPCore BREAKING: Renamed Connect() to ConnectAsync() in ModbusClient for clarity. --- EasyModbusTCPCore/ModbusClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EasyModbusTCPCore/ModbusClient.cs b/EasyModbusTCPCore/ModbusClient.cs index 29d28f7..856bc34 100644 --- a/EasyModbusTCPCore/ModbusClient.cs +++ b/EasyModbusTCPCore/ModbusClient.cs @@ -74,7 +74,7 @@ public ModbusClient() /// /// Establish connection to Master device in case of Modbus TCP. Opens COM-Port in case of Modbus RTU /// - public async Task Connect() + public async Task ConnectAsync() { if (debug) StoreLogData.Instance.Store("Open TCP-Socket, IP-Address: " + ipAddress + ", Port: " + port, System.DateTime.Now); @@ -92,7 +92,7 @@ public async Task Connect() /// /// Establish connection to Master device in case of Modbus TCP. /// - public async Task Connect(string ipAddress, int port) + public async Task ConnectAsync(string ipAddress, int port) { if (debug) StoreLogData.Instance.Store("Open TCP-Socket, IP-Address: " + ipAddress + ", Port: " + port, System.DateTime.Now);