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;
// If timeout we clean the buffer
if (Expired && (SizeAvail > 0))
try
{
byte[] Flush = new byte[SizeAvail];
TCPSocket.Receive(Flush, 0, SizeAvail, SocketFlags.None);
try
{
byte[] Flush = new byte[SizeAvail];
TCPSocket.Receive(Flush, 0, SizeAvail, SocketFlags.None);
}
catch
{
LastError = S7Consts.errTCPDataReceive;
}
}
catch { }
}
}
catch

View File

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