LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

recovering a tcp/ip connection

Hi Everyone,

 

I have a large VI that uses modbus tcp/ip to communicate with a remote sensor.  The problem is that is that if I disconnect the network cable or switch the power off to the sensor I get an error 56 from tcp read,  or I get error 66 from TCP write.  but I can not find away of clearing the error and re-estalishing the connection other than stopping and starting the VI.  Does anyone have any ideas as to where I can find what these errors mean, or better still how to deal with them.

 

Thanks in advance for any assistance.

 

Derek 

0 Kudos
Message 1 of 6
(3,132 Views)
Use a state machine architecture that has states for opening the port, closing the port, and all other normal running states you may have.  If you detect an error 56 or 66 as part of normal operation, then clear the error and go to the Open Port state again to reopen the connection.
Message 2 of 6
(3,113 Views)

Hi,

 

Thanks for that... that was a lot simpler than I thought it was going to be.

 

I did as you said and then, if I disconnected the power to the slave and re-connected, the connection would re-establish and all was well.  If however I pulled the network connection out wait for an error , then plug the network back in, wouldn't re-connect.  If I then cyled the power to the sensor, the connection would re-establish.   If I stopped the VI and restarted it I could re-connect.  What seems to have "fixed" the problem is if I close the connection befor I open it.  I know that sounds a bit odd but it seems to have worked.  I have attached the VI to this post.  If anyone has any explanation or comments please let me know.

 

Thanks again for your help

 

Derek

 

 

Message Edited by delbertson on 05-28-2009 08:59 AM
0 Kudos
Message 3 of 6
(3,091 Views)
You have to close the connection before trying to open it again. I don't understand why you think this is strange.
0 Kudos
Message 4 of 6
(3,076 Views)

I guess somewhere in my head the connection being "lost" is the same as being closed. I guess if you wouldn't try and open a com port without making sure it was closed so it makes sense.

 

Derek

0 Kudos
Message 5 of 6
(3,070 Views)

Hi there, me again.

 

Made a lot of progress with this.  What I've done is when I see a connection error I close the connection, then open a new one a second later, with the same IP and port number.  This works, but if I disconnect the network connection until the VI errors, then re-connect, I get an error 60 for almost exactly 2 mins then it re-connects.  It does this every time.

 

Although I've not been able to find a definitive explanation for this, I found this

 

http://digital.ni.com/public.nsf/allkb/119D334B8B78732E862574E1006D1839 

 

Which suggests that my client is in a Time Wait State, is this something that is fixed within the client, do I just have to live with this or is there a way I can 'force' the connection to timeout?  I'm off to try and find this out, but if anyone has any ideas that might help point me in the right direction I'd appreciate it.

 

Thanks again

 

Derek

 

0 Kudos
Message 6 of 6
(3,031 Views)