mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
Improved IsConnected and IsAvailable as shown in Issue #8.
Signed-off-by: Michele Cattafesta <michele.cattafesta@mesta-automation.com>
This commit is contained in:
@@ -18,6 +18,10 @@ namespace S7.Net
|
||||
public Int16 Slot { get; set; }
|
||||
public string Name { get; set; }
|
||||
public object Tag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pings the IP address and returns true if the result of the ping is Success.
|
||||
/// </summary>
|
||||
public bool IsAvailable
|
||||
{
|
||||
get
|
||||
@@ -27,18 +31,23 @@ namespace S7.Net
|
||||
return result != null && result.Status == IPStatus.Success;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the socket is connected and polls the other peer (the plc) to see if it's connected.
|
||||
/// This is the variable that you should continously check to see if the communication is working
|
||||
/// See also: http://stackoverflow.com/questions/2661764/how-to-check-if-a-socket-is-connected-disconnected-in-c
|
||||
/// </summary>
|
||||
public bool IsConnected
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mSocket != null)
|
||||
try
|
||||
{
|
||||
return _mSocket.Connected;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
if (_mSocket == null)
|
||||
return false;
|
||||
return !((_mSocket.Poll(1000, SelectMode.SelectRead) && (_mSocket.Available == 0)) || !_mSocket.Connected);
|
||||
}
|
||||
catch { return false; }
|
||||
}
|
||||
}
|
||||
public string LastErrorString { get; private set; }
|
||||
|
||||
Reference in New Issue
Block a user