diff --git a/S7.Net/PLC.cs b/S7.Net/PLC.cs
index cd44a13..40e148f 100644
--- a/S7.Net/PLC.cs
+++ b/S7.Net/PLC.cs
@@ -15,6 +15,9 @@ namespace S7.Net
private TcpClient tcpClient;
private NetworkStream stream;
+ private int _readTimeout = System.Threading.Timeout.Infinite;
+ private int _writeTimeout = System.Threading.Timeout.Infinite;
+
///
/// IP address of the PLC
///
@@ -44,17 +47,25 @@ namespace S7.Net
/// A that specifies the amount of time, in milliseconds, that will elapse before a read operation fails. The default value, , specifies that the read operation does not time out.
public int ReadTimeout
{
- get;
- set;
- } = System.Threading.Timeout.Infinite;
+ get => _readTimeout;
+ set
+ {
+ _readTimeout = value;
+ ConfigureConnection();
+ }
+ }
/// Gets or sets the amount of time that a write operation blocks waiting for data to PLC.
/// A that specifies the amount of time, in milliseconds, that will elapse before a write operation fails. The default value, , specifies that the write operation does not time out.
public int WriteTimeout
{
- get;
- set;
- } = System.Threading.Timeout.Infinite;
+ get => _writeTimeout;
+ set
+ {
+ _writeTimeout = value;
+ ConfigureConnection();
+ }
+ }
///
/// Returns true if a connection to the PLC can be established
@@ -122,6 +133,7 @@ namespace S7.Net
Slot = slot;
MaxPDUSize = 240;
}
+
///
/// Close connection to PLC
///
@@ -133,10 +145,18 @@ namespace S7.Net
}
}
- private void ConfigureNetworkStream(NetworkStream networkStream)
+ private void ConfigureConnection()
{
- networkStream.ReadTimeout = ReadTimeout;
- networkStream.WriteTimeout = WriteTimeout;
+ if (tcpClient != null)
+ {
+ ConfigureConnection(tcpClient);
+ }
+ }
+
+ private void ConfigureConnection(TcpClient client)
+ {
+ client.ReceiveTimeout = ReadTimeout;
+ client.SendTimeout = WriteTimeout;
}
#region IDisposable Support
diff --git a/S7.Net/PlcAsynchronous.cs b/S7.Net/PlcAsynchronous.cs
index 60851cc..91edb82 100644
--- a/S7.Net/PlcAsynchronous.cs
+++ b/S7.Net/PlcAsynchronous.cs
@@ -44,9 +44,9 @@ namespace S7.Net
private async Task ConnectAsync()
{
tcpClient = new TcpClient();
+ ConfigureConnection(tcpClient);
await tcpClient.ConnectAsync(IP, 102);
stream = tcpClient.GetStream();
- ConfigureNetworkStream(stream);
}
///
diff --git a/S7.Net/PlcSynchronous.cs b/S7.Net/PlcSynchronous.cs
index 556f490..ad7f737 100644
--- a/S7.Net/PlcSynchronous.cs
+++ b/S7.Net/PlcSynchronous.cs
@@ -50,9 +50,9 @@ namespace S7.Net
try
{
tcpClient = new TcpClient();
+ ConfigureConnection(tcpClient);
tcpClient.Connect(IP, 102);
stream = tcpClient.GetStream();
- ConfigureNetworkStream(stream);
}
catch (SocketException sex)
{