Connection status PLC
Closed this issue · 2 comments
The PLC.TcpClient.Connected does not return a valid value for whether the PLC is currently connected. The value returns true before data could be actually read. Is there a way to actually check the connection status that the PLC is ready for communication? Currently I am simply repeating the read until I do not receive an exception.
From TcpClient.Connected (emphasis by mine):
The
Connected
property gets the connection state of the Client socket as of the last I/O operation. When it returnsfalse
, theClient
socket was either never connected, or is no longer connected.
Is there a way to actually check the connection status that the PLC is ready for communication?
This is actually a more general problem of TCP and not specific to Sally7.
Afaik the only way to reliable check if it's ready for communication, is to send a (dummy) request. If it succeeds, then it's ready -- but note that a subsequent request may still fail due to network-errors, etc.
The best is to just try, and in case of failure re-try. Therefore you could use some library like "Polly".
In addition to the comment from @gfoidl, if you perform an Open()
(and it doesn't throw) and then check the Connected
prop it should be true
. At that point you actually are connected, I'm not sure if there's any way to check if the PLC is ready for communication.
In our applications we have a check whether exceptions are transient, but once I have successfully read a variable without any exception (retrying on transient exceptions only before that) I store that known-good state along the variable. If a PLC update is performed and there are intermittent address out of range exceptions I just ignore those and assume it'll all be good again at some point.
I'm closing this issue because I think it's all working as expected, but feel free to reopen with some more detail if you need further assistance.