12-08-2011 11:12 AM
I am using STM to pass communication between an HMI and a reat-time target. Everything works great unless the TCP connection is terminated on either end for whatever reason. How can I programitcally poll the port to see if the connection is still valid with out a read or write to the port?
Solved! Go to Solution.
12-08-2011 11:25 AM
LabVIEW doesn't have any sort of TCP "polling" VI. You'd have to perform a TCP-related operation and get the expected error to indicate the connection has been lost. What did you want to do once you found out whether the connection is no longer valid? Did you want to open a new connection and start using that one? If so, the best way to handle this is by trapping error conditions within your code. If you get the "connection terminated" error you'd open a new connection and retry the operation. I don't know how your code is structured, so I couldn't really tell you the best way to implement this within your code.
12-08-2011 12:54 PM
I was already doing that. Once I read/write I can then see if the connection is still valid and I reopen if it has closed. However, I was wondering if there was another way to poll the port without reading or writing to it.
12-08-2011 01:37 PM
I think you can do a read of 0 bytes, which should return immediately and return an error if the connection was properly closed. I don't believe it will ever return a timeout error. It will not tell you if the connection failed in some other way, like a disconnected network cable - in order for an error to occur there you need to try sending real data out.