LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview randomly freezes in while loop

Solved!
Go to solution

Hi everyone,

 

I'm fairly new to LabView, I like to think I've learned a lot through trial and error and reading this forum but I am stumped by something here. I hope somebody out there has some insight.

 

I have a program that controls a pump. I am communicating over a USB-to-serial cable. Typically the way my program works is that it sends a command to the pump, and then it immediately starts querying the pump for its status. I have the query in a loop that repeats every second. While the pump is moving it returns a Busy status, and when it finishes it returns a Ready status. When the program receives this Ready status, it exits the query loop and sends the next command.

 

I have a SubVI that queries the pump, and I use it in many places in my program. The problem is that while this works perfectly 95% of the time, 5% of the time the loop freezes for some reason. The timing of the freeze, location in the main program, and number of iterations of the loop that occur before the freeze are all random.

 

I have attached images of the front panel and block diagram of the subVI. The loop on the left is querying the pump, and the subVI within the subVI labeled as 2 is the communication with the pump over VISA. When I realized that the program was getting stuck in the loop I added the second (right) loop as a sort of "time out". If the program gets stuck at this point for a specified number of seconds, it should end the left loop. But that doesn't happen, the right loop stops but the left one never reads the True statement and stays stuck. LabView itself isn't frozen because I can go in and probe the wires.

 

Again, this is really hard to troubleshoot because it only happens 5% of the time or less. If anyone has any ideas as to why this might be happening I would be very grateful. I didn't think that posting the actual VI here would be helpful but please let me know if you want to take a look at it.

 

Thank you.

 

PS This has happened both in LabView environment and while running the EXE

0 Kudos
Message 1 of 31
(6,139 Views)

The VI you showed is odd that you have the two while loops in it.  I don't really understand why you did that, but I don't see why that is causing a problem as of yet.

 

If your subVI that reads your device is hanging up, nothing about two while loops is going to prevent that.  You need to show us the subVI that is doing the VISA communication.

 

Your comment "If the program gets stuck at this point for a specified number of seconds, it should end the left loop. But that doesn't happen, the right loop stops but the left one never reads the True statement and stays stuck" concerns me.  What True statement that is never read are you talking about?  You do know that once the local variable LED1 in the left loop is read, it is not read again until the loop iterates, don't you?  If the subVI is stuck, then the loop is going to remain stuck.

 

So show us the subVI.

Message 2 of 31
(6,119 Views)

Hi RavensFan,

 

Yes, I strongly suspected that the frozen loop was not going to read the LED and exit...this was a last-ditch, desperate effort. I was trying to think of a way to force the loop to exit somehow. In the original program there was only one loop.

 

Also, if there is any clue, if I shut down LabView while it is stuck in this loop I get a "ReSetting VI" error. The error never goes away and I have to close LabView using Task Manager.

 

I have attached all the relevant SubVIs, there are a few but very simple. The first is what I posted images of previously. The subVI "Send String to Pump and Receive Status" is just an adaptation of the "Advanced Serial Read and Write" that NI provides. The forum is only letting me post 3 files right now, the 4th just takes the string from the pump and interprets it into something meaningful (Busy, Ready, etc)

 

Thanks for having a look.

0 Kudos
Message 3 of 31
(6,107 Views)

And let me know if I should makes these LabView 8, right now they are LabView 2011

0 Kudos
Message 4 of 31
(6,106 Views)

Your Query pump subVI is pretty straight forward.  It just calls two other subVI's you didn't include.  What is going on in them?  Can you tell which of them is getting stuck?  (try opening the subVI's and watch probes.)

0 Kudos
Message 5 of 31
(6,099 Views)

I did include one of the other subVIs (Send string to pump and receive status) above, as I mentioned it is basically the same as the VISA read and write that NI provides. I've attached the other one here, it is also very straightforward.

 

I have tried keeping all the subVIs open and probing them before and after the program freezes. None of them seem to be getting stuck, I always see a query and immediately a response. But for whatever reason the loop just doesn't repeat.

 

I'm about to head home for the night but tomorrow I will see if I can get this to freeze again and then post a picture of the probes.

 

 

0 Kudos
Message 6 of 31
(6,088 Views)
Solution
Accepted by AJoneja

Repeatedly opening and closing the VISA session is generally not a good idea.  It is better to configure the port outside the loop, do th ereads and writes inside the loop and then close the session after the loop ends.  I would not be surprised if your serial port gets frozen due to the frequent opens and closes.

 

Ultimately you should learn about state machines.  That architecture would be appropriate for this type of program.

 

Lynn

Message 7 of 31
(6,078 Views)

Hi Lynn,

 

Thank you for your suggestion. I will definitely try to implement this tomorrow. I have two quick questions:

 

1. Do you have an idea of what a reasonable time is between port opening/closing? Even if I could make the loop every 5 sec instead of every 1 and it froze 5 times less frequently, that could be a stop-gap measure for now.

2. When I was trying to troubleshoot this I would start the pump and then unplug the cable. I would get a Timeout error from the VISA. I do NOT get this error when the program freezes in the loop. In the event that the serial port gets frozen, would I expect to see this error?

 

I haven't learned anything yet about state machines, but I will look into it and consider them for my next project.

 

Thank you,

Aric

0 Kudos
Message 8 of 31
(6,065 Views)

OK, before trying Lynn's suggestion I ran it a bunch of times today with probes on all the subVIs. It looks like it is definitely getting stuck in the "Send string to pump" subVI (see probes 8 and 9).

 

I'm going to move ahead and make the changes so that the opening/closing of the port is outside the loop. If any of the information here sparks a new idea, let me know!

0 Kudos
Message 9 of 31
(6,026 Views)

The string you are getting from your VISA read seems to be binary data.  (Look at the strangeness of the ASCII characters.)

 

But your interpretation of the data seems to be based on otherwise normal looking English characters.

 

Either two things are wrong.

 

1.  You are not truly interpreting your data correctly.

2.  You have your serial port parameters set incorrectly.  (What does the manual say?)  You are set with 8 data bits, no parity.  But if the device is sending 7 data bits with even or odd parity, that parity bit will change the value of the character you are reading if you are interpreting it as a data bit.

0 Kudos
Message 10 of 31
(6,021 Views)