From 2fbabd5517b7baa459fdac017bb9218883503d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BC=D0=B8=D1=80=D0=BD=D0=BE=D0=B2=20=D0=92=D0=B8?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=B8=D0=B9?= Date: Tue, 28 May 2019 10:01:28 +0300 Subject: [PATCH] style: updated code style. --- S7.Net/PLC.cs | 27 ++++++++++++--------------- S7.Net/PlcAsynchronous.cs | 2 +- S7.Net/PlcSynchronous.cs | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/S7.Net/PLC.cs b/S7.Net/PLC.cs index 40e148f..853c4ed 100644 --- a/S7.Net/PLC.cs +++ b/S7.Net/PLC.cs @@ -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; /// /// IP address of the PLC @@ -47,11 +47,11 @@ 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 => _readTimeout; + get => readTimeout; set { - _readTimeout = value; - ConfigureConnection(); + readTimeout = value; + if (tcpClient != null) tcpClient.ReceiveTimeout = readTimeout; } } @@ -59,11 +59,11 @@ namespace S7.Net /// 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 => _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 diff --git a/S7.Net/PlcAsynchronous.cs b/S7.Net/PlcAsynchronous.cs index 91edb82..291a938 100644 --- a/S7.Net/PlcAsynchronous.cs +++ b/S7.Net/PlcAsynchronous.cs @@ -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(); } diff --git a/S7.Net/PlcSynchronous.cs b/S7.Net/PlcSynchronous.cs index ad7f737..95d1baa 100644 --- a/S7.Net/PlcSynchronous.cs +++ b/S7.Net/PlcSynchronous.cs @@ -50,7 +50,7 @@ namespace S7.Net try { tcpClient = new TcpClient(); - ConfigureConnection(tcpClient); + ConfigureConnection(); tcpClient.Connect(IP, 102); stream = tcpClient.GetStream(); }