LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to kep TCP connection robust

Solved!
Go to solution

Hi,

Attached is a simple VI which communicates to a Ethernet-to-RS485 converter that is gathering data from a PLC. Static IP has been assigned to the converter & all is well if there is no power outage or looseness of the network cable.

If either of the above two conditions occur then Windows assigns a fresh connection ID resulting in communication failure.

How to take care of this situation?

Thanks.

0 Kudos
Message 1 of 8
(311 Views)

A very basic State Machine is what you need.  You start with a "Connect" state, which connects to the device.  Once a connection has been established, you can move on to the "Read" state.  This is the state you already have programmed up, trying to read data from your device.  When you want to stop the application, you move on to the "Close" state and stop your loop.  This is where your connection reference is closed.

 

Now if you detect an error during the read, often error code 66 for a closed network connection, you need to transition to the Close and then back to the Connect states.  This will allow you to attempt to reconnect to your device when there is an error.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(287 Views)

In addition to code changes as suggested, don't forget adding robustness to the physical setup as well.

 

Power failures?  Add a UPS.

 

Loose cables?  Buy better ones and/or use tie wraps to secure the ones you have in place better.

0 Kudos
Message 3 of 8
(268 Views)

Thanks for the inputs.

Yes state machines have to be used I understand.

Crossrultz do I use simple case structures to build the state machines? Can you please provide an example?

Thanks again.

0 Kudos
Message 4 of 8
(260 Views)

shantanu@india wrote:

Crossrulz do I use simple case structures to build the state machines? Can you please provide an example?


A simple state machine is based on a While Loop, Case Structure, and a Shift Register.  You may need an additional shift register so the Close state knows where to go next (Connect or Stop).

State Machine


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 8
(239 Views)
Solution
Accepted by topic author shantanu@india

Designed the same using state machines.

Absolutely bulletproof now!!

Thanks Crossrultz.

0 Kudos
Message 6 of 8
(178 Views)

shantanu@india wrote:

 

Absolutely bulletproof now!!

Thanks Crossrultz.


Are you sure it will survive something like this?

shot-computer.jpg

Rolf Kalbermatter
My Blog
Message 7 of 8
(139 Views)

Ha ha!

If that's a Desktop design then it gives me creeps... silent assassin lurking behind me

0 Kudos
Message 8 of 8
(126 Views)