Hello,
I have a small issue about the ConnectionTimeout property of the ModbusClient class, which I find a bit deceiving, since it's not used when creating the TcpClient object.
Would it be possible to change the following instruction in the Connect method of ModbusClient class:
tcpClient = new TcpClient(ipAddress, port);
to something like:
tcpClient = new TcpClient();
var result = tcpClient.BeginConnect(ipAddress, port, null, null);
var success = result.AsyncWaitHandle.WaitOne(connectTimeout);
if (!success)
{
// throw an exception, for example a socket timeout:
throw new SocketException(10060);
}
tcpClient.EndConnect(result);
In alternative it could be used the TcpClient.ConnectAsync method, but in that case the target Framework of the EasyModbusAdvancedClient project should be raised to 4.5.
Thank you.
Alberto
EDIT:
It should also be changed the following code in the destructor of ModbusClient:
if (tcpClient != null & !udpFlag)
to
if (tcpClient != null && tcpClient.Connected && !udpFlag)
Last edit: Alberto 2017-02-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have a small issue about the ConnectionTimeout property of the ModbusClient class, which I find a bit deceiving, since it's not used when creating the TcpClient object.
Would it be possible to change the following instruction in the Connect method of ModbusClient class:
tcpClient = new TcpClient(ipAddress, port);
to something like:
tcpClient = new TcpClient();
var result = tcpClient.BeginConnect(ipAddress, port, null, null);
var success = result.AsyncWaitHandle.WaitOne(connectTimeout);
if (!success)
{
// throw an exception, for example a socket timeout:
throw new SocketException(10060);
}
tcpClient.EndConnect(result);
In alternative it could be used the TcpClient.ConnectAsync method, but in that case the target Framework of the EasyModbusAdvancedClient project should be raised to 4.5.
Thank you.
Alberto
EDIT:
It should also be changed the following code in the destructor of ModbusClient:
if (tcpClient != null & !udpFlag)
to
if (tcpClient != null && tcpClient.Connected && !udpFlag)
Last edit: Alberto 2017-02-03