fixed exception handling

- minor fixes in curly brackets
This commit is contained in:
Federico Barresi
2020-05-07 00:12:12 +02:00
parent 80bda05e2f
commit a073997211
2 changed files with 20 additions and 16 deletions

View File

@@ -97,12 +97,17 @@ namespace Sharp7
Expired = Environment.TickCount - Elapsed > Timeout; Expired = Environment.TickCount - Elapsed > Timeout;
// If timeout we clean the buffer // If timeout we clean the buffer
if (Expired && (SizeAvail > 0)) if (Expired && (SizeAvail > 0))
{
try try
{ {
byte[] Flush = new byte[SizeAvail]; byte[] Flush = new byte[SizeAvail];
TCPSocket.Receive(Flush, 0, SizeAvail, SocketFlags.None); TCPSocket.Receive(Flush, 0, SizeAvail, SocketFlags.None);
} }
catch { } catch
{
LastError = S7Consts.errTCPDataReceive;
}
}
} }
} }
catch catch

View File

@@ -497,22 +497,17 @@ namespace Sharp7
private int Time_ms = 0; private int Time_ms = 0;
private void CreateSocket() private void CreateSocket()
{
try
{ {
Socket = new MsgSocket(); Socket = new MsgSocket();
Socket.ConnectTimeout = DefaultTimeout; Socket.ConnectTimeout = DefaultTimeout;
Socket.ReadTimeout = DefaultTimeout; Socket.ReadTimeout = DefaultTimeout;
Socket.WriteTimeout = DefaultTimeout; Socket.WriteTimeout = DefaultTimeout;
} }
catch
{
}
}
private int TCPConnect() private int TCPConnect()
{ {
if (_LastError==0) if (_LastError==0)
{
try try
{ {
_LastError=Socket.Connect(IPAddress, _PLCPort); _LastError=Socket.Connect(IPAddress, _PLCPort);
@@ -521,6 +516,7 @@ namespace Sharp7
{ {
_LastError = S7Consts.errTCPConnectionFailed; _LastError = S7Consts.errTCPConnectionFailed;
} }
}
return _LastError; return _LastError;
} }
@@ -575,9 +571,12 @@ namespace Sharp7
// Receives the S7 Payload // Receives the S7 Payload
RecvPacket(PDU, 7, Size - IsoHSize); RecvPacket(PDU, 7, Size - IsoHSize);
} }
if (_LastError == 0) if (_LastError == 0)
{
return Size; return Size;
else }
return 0; return 0;
} }