diff --git a/S7.Net/PLC.cs b/S7.Net/PLC.cs
index 284b81b..cd44a13 100644
--- a/S7.Net/PLC.cs
+++ b/S7.Net/PLC.cs
@@ -39,6 +39,22 @@ namespace S7.Net
/// Max PDU size this cpu supports
///
public Int16 MaxPDUSize { get; set; }
+
+ /// Gets or sets the amount of time that a read operation blocks waiting for data from PLC.
+ /// 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;
+
+ /// 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;
///
/// Returns true if a connection to the PLC can be established
@@ -117,6 +133,12 @@ namespace S7.Net
}
}
+ private void ConfigureNetworkStream(NetworkStream networkStream)
+ {
+ networkStream.ReadTimeout = ReadTimeout;
+ networkStream.WriteTimeout = WriteTimeout;
+ }
+
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
diff --git a/S7.Net/PlcAsynchronous.cs b/S7.Net/PlcAsynchronous.cs
index fe3c552..60851cc 100644
--- a/S7.Net/PlcAsynchronous.cs
+++ b/S7.Net/PlcAsynchronous.cs
@@ -46,6 +46,7 @@ namespace S7.Net
tcpClient = new TcpClient();
await tcpClient.ConnectAsync(IP, 102);
stream = tcpClient.GetStream();
+ ConfigureNetworkStream(stream);
}
///
diff --git a/S7.Net/PlcSynchronous.cs b/S7.Net/PlcSynchronous.cs
index bdc40bf..556f490 100644
--- a/S7.Net/PlcSynchronous.cs
+++ b/S7.Net/PlcSynchronous.cs
@@ -52,6 +52,7 @@ namespace S7.Net
tcpClient = new TcpClient();
tcpClient.Connect(IP, 102);
stream = tcpClient.GetStream();
+ ConfigureNetworkStream(stream);
}
catch (SocketException sex)
{