01-24-2017 05:07 AM
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
01-24-2017 06:48 AM - edited 01-24-2017 06:51 AM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
01-24-2017 06:54 AM
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
01-27-2017 02:12 AM
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
01-27-2017 02:21 AM - edited 01-27-2017 02:22 AM
01-27-2017 05:56 AM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
02-01-2017 10:56 PM
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.
02-01-2017 10:59 PM
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
02-02-2017 01:03 AM
Hello Dushy_11,
no code was attached in the previous post.
What do you mean with glitches?
02-03-2017 04:06 AM
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