LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While/For Loop and resetting the i value in the while loop

Solved!
Go to solution

yeah, i can't set the Pause to anything other than ON.

Because if I set it OFF..the system will not be in that mode.

ideally, my program is structured in this form.

 i was working for hours on the actually system, but i noticed that it is easier to break down the code and do a simulation and not deal with any hardware issue.

 

the current program is to scan the devices starting at position 0 to 50 for instant.

but it only increment by 1. so if i am at position 40. and i forgot or didnt see something. in order for me to go to position 40 again.

i have to increment about another 50 times in order to get to that position again.

thats why i need this loop to work probably, so that if i decided to A DESIRED POSITION..i can easily do it..

 

Message Edited by Giangliang on 02-13-2009 09:22 PM
0 Kudos
Message 11 of 14
(1,082 Views)

This looks just like your code from message 1.  Have you made or tried any changes?

 

Your overall For Loop will only run 5 times.  You won't be able to get the Pause button (I think that is your button named "Boolean") to execute until you hit the Next Position button to end your while loop inside the For Loop.  That's because the Pause button has already been read before the while loop began.  Once that happens you are onto your next iteration of the For loop.

 

Before you go any further, I suggest you look at the message threads dealing with "State Machines".  Also look at the examples in LabVIEW on this.  A state machine has basically one master loop.  Inside of that is a case structure where each case represents a single state such as Pause, Run, Advance Position, Back Position, Initialize, Close, ....  .  Data is carried between iterations by way of shift registers.  One of those is a shift register that stores an enum value (Preferable type def'ed) to tell which state will be the state to execute on the next loop iteration.    Depending on what buttons are pressed, how many Positions you've stepped through you will have a decision tree to determine what is the next state you execute.

 

State machines give you a lot of flexibility.  Trying to tie together a couple while loops or For loops as you are doing now is just going to program yourself into a corner.  Even if you manage to get it working exactly like you want, you'll probably wind up breaking everything once you find you need to handle another condition or need to expand the code a bit.

Message 12 of 14
(1,077 Views)
Message Edited by krispiekream on 02-13-2009 10:46 PM
Best regards,
Krispiekream
0 Kudos
Message 13 of 14
(1,074 Views)

i think Ben code looks like it will work. after i modify something.

I tried the reset[1].vi as well..it is the same as ben's version by in different form...

i guess i wasn't clear in describing the details of the routine. 

but yeah, the PAUSE button always have to be ON..

I made this and it seems to work.

I am just not happy that I have to press a button in order to go to the desired position.

but here it is..

0 Kudos
Message 14 of 14
(1,071 Views)