LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Troubles using while loops and case loops

Hi, i have accounted a lot of problems using labview 6.02 with field point. My main problem was that originally i had trouble running two while loops at once and been able to control them independently e.g. start and stop each loop when i want, but i have also come up with a separate problem. when using case loops with while loops, i can not seem to to get them to work properly. Like say if i have a program with while loops and i want to switch something on and off using a case loop its not possible. An example of this are below, any help greatly appreciated.

Thanks Stuart
0 Kudos
Message 1 of 9
(3,724 Views)
Stu,

I looked at your example - couldn't run it, since I don't have the Field Point VI's, but I an observation. In your main VI, you have two parallel while loops that run independently, and the case structure is outside both of them - this will only be evaluated once - you need a way to poll the case, maybe in its own loop. Hope this helps.
Message 2 of 9
(3,724 Views)
Hiya Stuart!

I've looked at your example and the only case structure i can find is the one linked to a button called 'Boolean 2'. This button is only read once at the very start, so the case loop will only run through once as well. If you put this case structure and Boolean 2 button in a while loop, then the value in the button will be read at the start of every loop (the loop it is in), and the case structure will run through on every iteration of the loop.

I have updated your example to show this.

Point to note: There is no such thing as a case loop, but there is a case structure. This runs through once, and does not loop.

I hope this helps you...(and it's good to see how your program is progressi
ng! *smiles*)

Kim
0 Kudos
Message 3 of 9
(3,724 Views)
One thing, your close session executes right after you create the tags. It's not data dependant on either of the while loops terminating.Unless enclosed in another loop, or dynamically called, once your loop is stopped, it's stopped.
Message 4 of 9
(3,724 Views)
Thanks for the comments. What i mean about running independently is that, i can start one loop then 5 mins later start the second loop and stop the second loop and restart it if need be and for some reason that is not possible as for th case loop i have tried putting a while loop around it. So that it will run, and so i can select different vi's, but for some unknown reason it does not work and i have talked to an application engineer from NI and they even say it should work. So i'm waiting for the application engineer to solve the problem. But thanks for your comments any way.

Stuart
0 Kudos
Message 5 of 9
(3,724 Views)
Hi Kim, thanks but already tried this and got talking to an NI application engineer and they suggested this. And they also said this should work. So i'm going to let the application engineer have a look and if it works with him. Its then got to be a hardware or software problem.

Anyway thanks
0 Kudos
Message 6 of 9
(3,724 Views)
If the intention of your program is to be able to start, stop, restart whatever code is inside the while loops, you're going to have to make some changes. Once you stop a while loop, it will not restart until you restart the whole VI. Enclosing everything in another while loop and putting case structures inside the sub while loops is one way to go. I've attached a small VI that I hope will demonstrate what I mean.
0 Kudos
Message 7 of 9
(3,724 Views)
> Thanks for the comments. What i mean about running independently is
> that, i can start one loop then 5 mins later start the second loop and
> stop the second loop and restart it if need be and for some reason
> that is not possible ...



I haven't looked at your VI, but from the other description, I think
that it is clear what is going on.

Any given diagram in LV will execute all nodes on it exactly once before
it can be scheduled to run again. In this case, the loops will not
begin running again until the case finishes and begins running again.

To resolve this, do not let the while loop stop until you really want
the case to exit. In otherwords, the contents of the loop can be made
conditional and can execute in the TRUE, but sim
ply wait ms in the FALSE
case.

Greg McKaskle
0 Kudos
Message 8 of 9
(3,724 Views)
Thanks, this has been the main cause of my trouble and have solved it now. But from now on, i think i will stick to using DAQ than field point as is more flexible and u do not have to use loops to use it in this particular task.

Thanks Stu
0 Kudos
Message 9 of 9
(3,724 Views)