LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect a lost TCPIP SOCKET using LabVIEW and NI VISA

Solved!
Go to solution

I am using VISA functions in LabVIEW to remotely communicate with instruments over TCPIP SOCKET visa resources.   In general this all works well by simply creating a resource name, passing it to VISA Open and then setting a couple of session attributes.   Occasionally an instrument will be reset or power cycled and what I have noticed is that I need to call a VISA Close and then reopen the resource in order to get it to communicate again or close LabVIEW and run again.   If you just use VISA Open without calling a VISA Close first you cannot communicate with the target.   The problem is that I have no way of detecting this condition.   I have tried always calling a VISA Close before VISA Open and this seems to work for this condition but it seems odd to always close a session before opening it.   Why does VISA OPEN not work under this condition and is there any way to detect this situation?

0 Kudos
Message 1 of 3
(3,162 Views)
Solution
Accepted by topic author darrenj

It works that way because that is how TCP works. A TCP connection is a dedicated connection between two endpoints. Unfortunately other than getting an error from a read or write operation there is no way to determine if the othe rside of teh connection is still there. You need to close the connection because otherwise VISA will continue to use th eold connection which is no longer valid. Closing it allows the system to cleanup the dead connection.

 

If you are communicating fairly infrequently you could simply open the connection, do you stuff and close it. The overhead for establishing the new connection is not that much. If you are using steady streams of data then you will need to watch for the errors and then reestablish the connection by closing the old one and opening a new connection as you have observed.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 3
(3,159 Views)

Thanks Mark.

0 Kudos
Message 3 of 3
(3,124 Views)