feature: added ReadTimeout and WriteTimeout to PLC class for NetworkStream.

This commit is contained in:
Смирнов Виталий
2019-05-27 13:52:38 +03:00
parent e623b535ac
commit 0dbe401ce9
3 changed files with 24 additions and 0 deletions

View File

@@ -39,6 +39,22 @@ namespace S7.Net
/// Max PDU size this cpu supports
/// </summary>
public Int16 MaxPDUSize { get; set; }
/// <summary>Gets or sets the amount of time that a read operation blocks waiting for data from PLC.</summary>
/// <returns>A <see cref="T:System.Int32" /> that specifies the amount of time, in milliseconds, that will elapse before a read operation fails. The default value, <see cref="F:System.Threading.Timeout.Infinite" />, specifies that the read operation does not time out.</returns>
public int ReadTimeout
{
get;
set;
} = System.Threading.Timeout.Infinite;
/// <summary>Gets or sets the amount of time that a write operation blocks waiting for data to PLC. </summary>
/// <returns>A <see cref="T:System.Int32" /> that specifies the amount of time, in milliseconds, that will elapse before a write operation fails. The default value, <see cref="F:System.Threading.Timeout.Infinite" />, specifies that the write operation does not time out.</returns>
public int WriteTimeout
{
get;
set;
} = System.Threading.Timeout.Infinite;
/// <summary>
/// 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

View File

@@ -46,6 +46,7 @@ namespace S7.Net
tcpClient = new TcpClient();
await tcpClient.ConnectAsync(IP, 102);
stream = tcpClient.GetStream();
ConfigureNetworkStream(stream);
}
/// <summary>

View File

@@ -52,6 +52,7 @@ namespace S7.Net
tcpClient = new TcpClient();
tcpClient.Connect(IP, 102);
stream = tcpClient.GetStream();
ConfigureNetworkStream(stream);
}
catch (SocketException sex)
{