LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Auto reconnect Serial session

Solved!
Go to solution

I have coded a simple VI to keep sending a data string over Serial port to a connected device. The data string contains a mix of Boolean and string variables.

The code works OK. But i have a problem when something happens to the connected serial device and the data writes do not happen even for a few cycles. I wait for 10 secs and give the user a choice to wait or restart.

Though i say "WAIT" it is of no use - as i can see that once the link is broken it cannot re-establish even if the connected serial device comes alive. 

 

How does one handle this situation - meaning to auto recover the serial link after a break ? The VIs are done in LV2015. The starting VI is ChoseCOMport.VI.

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
Download All
0 Kudos
Message 1 of 12
(6,088 Views)

I see a few issues.

 

1.  Your two subVI's are password protected so we can't see in them.  Are they meant to be a secret?  I don't know if anything significant is happening in them.

2.  You have a race condition with Bytes Written since you are using a local variable.  That local variable is probably read before the value is written to the terminal.

3.  Your logic for determining if 10 seconds have passed is very convoluted.  Within 3 seconds it will be greater than 3, and than always will be.

4.  Your Bytes Written=0.  Why do you think that will tell you a device is disconnected?  Is this a normal serial connection?  You can lose a device on a serial cable, but the com port still exists.  And it will still send out data when written to the serial port even if something is not there to listen.

 

Typical logic to determine a lost connection would be if there is an error on a serial command, or if you write a command out, and don't get a response, in the expected time.  Perhaps you give a couple of retries before declaring the connection is dead.

0 Kudos
Message 2 of 12
(6,073 Views)

Thanks Revan. Nice to get your detailed response as ever.

 

1. Secret ?!! I am so sorry. Have removed the protection and posting again.

2. Agreed - it can get into a race situation.

3. Yes this will be greater than 3 sec always but i thought it will satisfy the compare criteria ?

4. Possibly I am not clear on the Bytes Written ... as I could see the moment I remove the Serial Device from the connected port, the BytesWritten do become zero. So I thought it needs a listener to update the status.

 

...perhaps you give a couple of retries...

Would be happy to see a small example on this.

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
Download All
0 Kudos
Message 3 of 12
(6,059 Views)

OK now I am using the Error out from the Write To Serial function. This removes the race condition of the Bytes Written. It works but still an interrupted session ( receiving device removed ) unable to reconnect. Not sure how to go about doing this .

 

In the meanwhile have been stuck with another issue - The Installer of this project created with the App Builder does not run on another PC which earlier did not have LV.  When I say not working its the COM port choosing field which turns up empty always when the application is launched. And the WIN-8 machine on which App was tried shows two active COM ports in the Device manager setup . What could be causing this ??

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 4 of 12
(5,992 Views)

Show the VI that you have now.

 

For the installer, did you include the VISA drivers when you built the installer after doing the build process for the .exe?

0 Kudos
Message 5 of 12
(5,987 Views)

I have attached the modified VI ..

 

On the aspect of the COM ports not being enumerated I think you hit the right point. Yes when I built the Installer I used the "Automatically select additional installer " option. Now after reading your post I went back and unchecked the selection. I see a big list as below ....now should I include all with the VISA name ?

AdditionalInstaller list 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 6 of 12
(5,983 Views)
Solution
Accepted by topic author MogaRaghu

Why would you uncheck it after reading my post?  Automatically select being checked allows LabVIEW to tell you what other installers that should be added because you are using features like VISA.  So of course you should include VISA because how else would a computer without LabVIEW know how to use the VISA functions without those drivers.

 

As for reconnecting, right now you just ask if it should close the program.  If you get an error, but the user says "Try Again" or "WAIT" as you have, then you should have that selection drive a case structure that will actually wait a bit, then try to configure the serial port again.  Make sure the VISA reference wire is on a shift register so that if it reconnects and gets a new reference number, the next iteration of the loop uses that reference.  Right now, your next iteration will just use the original because that is what is at the input tunnel, and that one is no longer valid.

Message 7 of 12
(5,980 Views)

First the good news. I have been able to bring in code to re-start a failed Serial session within the timed loop - see the code below : 

SigmaSim.png

 

Thanks for the pointer you gave on above. 

 

However the Installer plays truant still - it does not include the VISA run time automatically. I have to manually add it in the additional installer page. And then something funny happened : I had given the Installer Destination (for storing the installer build ) on the first page as A:\xyz\Abc\ as all my data resides in A: drive. 

And once when i completed the build i tried to run it on another PC and the SETUP complained saying it cannot find A: drive and exited. I thought its not my day and stopped. 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 8 of 12
(5,960 Views)

That looks just like the way I was thinking for reconfiguring the serial port.

 

I know that the builders seem to do a good job in figuring out what other installers need to be included.  Maybe once you unselect something, it might remember that you did that.  Try deleting the build spec and recreating another one from scratch.  (Actually, I think you can just create a new one from scratch and don't have to delete the original one first.)  See if the new one recognizes if it needs VISA.

 

It is very odd that it would be asking for an A:\ drive.  A:\  and B:\ drives were always floppy drives which PC's don't have anymore.  I haven't seen a drive letter like that on a PC in at least a decade.  I imagine that it would be possibly to manually map another hard drive or a network drive to A:\, but I don't know of anyone who has ever done that.

 

Just try recreating a new installer build spec. from scratch.

0 Kudos
Message 9 of 12
(5,952 Views)

Hi MogaRaghu, 

 

Are you able to share this last Vi? I'm having the same problem, when the serial port is disconnected and connected again it is not possible to continue with the process. I'm using labVIEW 2014.

 

Thanks in advance. 

 

 

0 Kudos
Message 10 of 12
(5,141 Views)