LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP/IP communication interrupted when my device turns OFF and then powered up again

Dear All

I have developed an application where i am communicating with the device through TCP/IP Protocol. Application runs absolutely fine.But problems comes when the device with whom my Application is communicating turns off by any reason, so when device gets powered up again, the communication does not start again automatically.
For that, i need to exit the application and start it again for establishing the communication and then communication works fine.
Kindly help me out with your expertise to overcome this problem. So that i dont need to exit out of my application each time the device gets down and again gets powered up.

 

Thanks in advance

 

Dushyant Sharma

0 Kudos
Message 1 of 16
(4,059 Views)

You have to plan for such things in your LV code.  Basically, you need another level of Loop, outside whatever you have now, and you have to watch for errors.

 

Something like:

 

ConnID = NaN   // start with not-a-refnum (no connection)

REPEAT  (while loop)

   if ConnID = NaN           // if connection is down

        ConnID, Err = TCP CONNECT (IPAddr, Port, Timeout = 1000 mSec)

   if ConnID != NaN

        ConnID, Err = Send Command to Box (my Command, timeout = 100 mSec);

        if Err = noErr   // if no error

             ConnID, Err = Receive Data from My Box (nBytes, timeout = 200 mSec)

        case Err of    // check the type of error

        noErr:  DoSomethingUseful( );

        timeOut:  MaybeExtendTheTIMEOUTPeriod( )

        62,66, maybe others:

            TCP Close Connection (ConnID)

            ConnID = NaN  // signal that connection is down

until STOPPED.

 

Here, "NaN" refers to an empty TCP RefNum, which you can test with the Not-a-Refnum operation.

 

Basically, you watch for errors, and if the connection is killed, you attempt to reconnect.

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 16
(4,024 Views)

Hello Dushy_11,

 

normally the TCP/IP functions return an error if the connection to the TCP server is lost. You can use this error to restart the connection to your device so every time the connection is lost a restart will be executed.

This is for the server side, if error 56 happend the error will be cleared and the loop restart.

Reconnectable TCP Server Connection

best regards
Alexander
0 Kudos
Message 3 of 16
(4,020 Views)

Hello

 

Thanks for your precious suggestions.

I am attaching my code. Pls guide and tell what need to be done to resolve my problem.

I will be highly thankful to you.

 

Thanks

Dushyant

0 Kudos
Message 4 of 16
(3,976 Views)

Hello Dushy_11,

 

you can add something like this, but it is not tested.

Capture.PNG

best regards
Alexander
0 Kudos
Message 5 of 16
(3,974 Views)

Pls guide and tell what need to be done

 

I've already said what needs to be done.

 

Your code shows not the slightest sign that you attempted anything like what I said above.

 

you're not event trying to reconnect.

 

You stop the loop on any error, and THEN you convert the error to a warning.

 

Good luck.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 16
(3,963 Views)

Hi Alexander

 

Sorry for posting late as i was out of town and cud not implemented your suggestion.

I did that now but dat also dint work. Then i implemented  a logic on my own and it worked for me but with few glitches.

To remove the glitches, i will be needing the help of you all Labview experts

I will post the code soon, so that you all can analyze where i am going wrong.

 

Thank you so much for your valuable suggestions.

0 Kudos
Message 7 of 16
(3,935 Views)

Hi steve

 

I took all your suggestions and modified my code accordingly. Its working as desired but with 1-2 glitches.

I will share the modified code here for you to help me in rectifying those glitches

 

Thank you so much

Dushyant

0 Kudos
Message 8 of 16
(3,934 Views)

Hello Dushy_11,

no code was attached in the previous post.

What do you mean with glitches?

best regards
Alexander
0 Kudos
Message 9 of 16
(3,927 Views)

Hello,

Attached pls find my modified VI to resolve the said problem. This VI is working fine even when i am interupting the power supply in between and switching on the power supply again.
But the problem comes when i am opening another Sub VI from this main VI and communicating through TCP/IP in this Sub VI by taking the Connection ID of the MAIN VI.I am not able to communicate.

Earlier before implementing this logic, i was able to communicate in my SUB VIs with the same connection ID

So in my previous posted VI, i was able to communicate through TCP/IP in my Sub VIs but i was having Power supply interruption problem
And now with this VI, power supply interruption problem has been soughted out but now i am not able to communicate through TCP/IP in my Sub VIs

 

Pls guide

 

Thanks in advance

Dushyant

0 Kudos
Message 10 of 16
(3,912 Views)