style: updated code style.

This commit is contained in:
Смирнов Виталий
2019-05-28 10:01:28 +03:00
parent 800a790b89
commit 2fbabd5517
3 changed files with 14 additions and 17 deletions

View File

@@ -15,8 +15,8 @@ namespace S7.Net
private TcpClient tcpClient;
private NetworkStream stream;
private int _readTimeout = System.Threading.Timeout.Infinite;
private int _writeTimeout = System.Threading.Timeout.Infinite;
private int readTimeout = System.Threading.Timeout.Infinite;
private int writeTimeout = System.Threading.Timeout.Infinite;
/// <summary>
/// IP address of the PLC
@@ -47,11 +47,11 @@ namespace S7.Net
/// <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 => _readTimeout;
get => readTimeout;
set
{
_readTimeout = value;
ConfigureConnection();
readTimeout = value;
if (tcpClient != null) tcpClient.ReceiveTimeout = readTimeout;
}
}
@@ -59,11 +59,11 @@ namespace S7.Net
/// <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 => _writeTimeout;
get => writeTimeout;
set
{
_writeTimeout = value;
ConfigureConnection();
writeTimeout = value;
if (tcpClient != null) tcpClient.SendTimeout = writeTimeout;
}
}
@@ -147,16 +147,13 @@ namespace S7.Net
private void ConfigureConnection()
{
if (tcpClient != null)
if (tcpClient == null)
{
ConfigureConnection(tcpClient);
return;
}
}
private void ConfigureConnection(TcpClient client)
{
client.ReceiveTimeout = ReadTimeout;
client.SendTimeout = WriteTimeout;
tcpClient.ReceiveTimeout = ReadTimeout;
tcpClient.SendTimeout = WriteTimeout;
}
#region IDisposable Support

View File

@@ -44,7 +44,7 @@ namespace S7.Net
private async Task ConnectAsync()
{
tcpClient = new TcpClient();
ConfigureConnection(tcpClient);
ConfigureConnection();
await tcpClient.ConnectAsync(IP, 102);
stream = tcpClient.GetStream();
}

View File

@@ -50,7 +50,7 @@ namespace S7.Net
try
{
tcpClient = new TcpClient();
ConfigureConnection(tcpClient);
ConfigureConnection();
tcpClient.Connect(IP, 102);
stream = tcpClient.GetStream();
}