LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Proper method to reset tcp connection after timeout error

Solved!
Go to solution

I have a application that I am building that communicates with a Modbus TCP device.  If a communications error occurs I would like to be able the reset the TCP communications.  What I have is a control that fires a event when pushed.  In this event I have a sequence that first closes the tcp connection and then opens a new connection.  My applications starts and runs fine.  To test the reset function I removed the ethernet cable from the device and waited of a timeout to occur.  I plugged the cable back in and pushed my reset control. Occasionally the reset will occur but most times I will get a time out error at the Open TCP vi.  After this, the only way I can establish communications is to exit my application, disable and then enable my network device.  Then when I restart my application I have communications with my device.

 

Any help would be appreciated on how I should be resetting my TCP connection.

 

Thanks

 

Terry

0 Kudos
Message 1 of 5
(5,606 Views)

How are you directing LabVIEW to the network device? It makes sense that you get a timeout error if the device is still working out connection settings or is assigned different connection settings when you are trying to connect to it.

 

Also, does your program try to reconnect again in the case of a timeout?

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
0 Kudos
Message 2 of 5
(5,579 Views)

I have attached a example vi (LV10)  that shows just the TCP connection and Reset.  An error will occur when trying to perform the open tcp in the reset event.

0 Kudos
Message 3 of 5
(5,575 Views)
Solution
Accepted by topic author Terry_S

@terry S wrote:

I have attached a example vi (LV10)  that shows just the TCP connection and Reset.  An error will occur when trying to perform the open tcp in the reset event.


As written your code should be fine. There is nothing inherently wrong with it. However depending on the device you are communicating with you may be trying to reestablish the connection too quickly after you closed the connection. The device may not allow multiple connections to it and may require sometime to clean things up on its end after you close a connection. As an experiment trying waiting a short time between the TCP Close and the TCP Open. If possible you may want to try using Wireshark to see what is happening on the network. It can be useful in diagnosing what is going on.



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 4 of 5
(5,551 Views)

Thanks Mark, adding a time delay between the open and close seems to be working.

0 Kudos
Message 5 of 5
(5,535 Views)