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

Hi!

I have a question about using the while/for loop.

I am reading data from 5 devices.

Start with position 0 when i=0, i read data at position 0.

And  when I click on NextPosition, then i=1, and stop when i=5.

But in the mean time, if I want to pause the system from position 3 for instant. I click on the PAUSE.

I choose the desired position to be back at 0, it will go to that position.

But If I click on NextPosition, the value is still my 0 and not the 1, which is the next position up.

Also, everytime I click on NextPosition, it will count up to i=5 and stop the program.

Is there any way I can approach this?

 

 

 

 

Message Edited by Giangliang on 02-13-2009 11:57 AM
Download All
0 Kudos
Message 1 of 14
(6,862 Views)

Search the LabVIEW help for info on "Shift Registers". THey are a special feature available in most of the looping structures that allow you BOTH read and write to the same data value. This lets you use the result of a previous iteration in latter iterations OR when combined with a case structure, let you rest a value.

 

have fun!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 14
(6,849 Views)

i did this, but i think it only work for the first time that i change the value of the desired position.

if i change the number more than once, it remember the last number in the shift register. 

 

 

Message Edited by Giangliang on 02-13-2009 01:26 PM
Download All
0 Kudos
Message 3 of 14
(6,823 Views)

I believe I could answer your question directly but I would rather share another technique that works great for me when I am trying ot figure out why my code is not working.

 

Turn on "Execution Highlighting" (the light-buld button on the Block Diagram).

 

Watch your data* as it moves through the diagram while you are pushing your buttons etc.

 

While watching if you see data going somewhere you or things happening un-expectedly, then you will get a clue as to how to change you wiring to achieve your end.

 

Please try that and then post back if you still need more advice.

 

Ben

 

* You know you have watched too many diagrams run in execution highlighting when you can predict which node will execute next.

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 14
(6,815 Views)

yeah, i turn it on, but i still dont see it. i dont want to get into event structure.

it seems like the value that i change to is added on becuase i have pause=true and nextposition=true.

the value that i changed to is outside of the inner loop. but when the two conditions are true, the local variable for desired position is changed. i didn't reset it yet. 

can you give me another clue..

 

0 Kudos
Message 5 of 14
(6,802 Views)
Solution
Accepted by topic author Giangliang

Thank you for trying!

 

I am not sure what your actual requirements are so I am guessing that you want to keep hitting the same device until you hit the Next Device button and you want to be able to specify which one next.

 

In the attached code I changed your pause button mechanical action and renamed it to Reset Position.

 

I also changed the code suchthat we conditionally increment the device number (only when next button hit).

 

I alos moved the local so we are not writting over and over and put it in the rest case structure so it either written or read but not both.

 

If this does not meet your needs;

 

1) Watch in light-bulb mode and see where I messed up

 

2) If you can't figure it out put together a truth table of all of the buttn combinations and doc what action should happen for each condition.

 

Still trying to help,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 14
(6,785 Views)

Hi,

 

If i understood ur Question correctly. Attached vi might help u.

Check it up and let me know.

 

 

 

Rgds,

Venky 

Message 7 of 14
(6,779 Views)
Because your stop conditon is still based on the i terminal.  Your overall while loop will only run 5 times.  And with not time delays in the loop, that will look instantaneous.  So you may run step 0 5 times if you are paused.  I think you proably want to compare the wire going into the shift register with 5, not the i terminal.
Message 8 of 14
(6,772 Views)

Yeah, the reset.vi doesn't work.

I am not able to change any value because "i" changes from 0-5 very fast and it stop the loop.

 

But Ben, you got the right idea. That's what I wanted to do, except for one thing,. i cant set the mechanical action to latch when released. It has to switch when pressed.

Is there any other around it?

 

I don't want to hit the same device if  Reset Position is pressed,

I want to Reset to that position once, and click next position, it should increment by 1. 

But during any moment, I want to change the desired position to something else, it would go there as well.

then increment from that point on. 

 

i think its a little bit tricky, but there has to be a way..

 

 

Message Edited by Giangliang on 02-13-2009 04:38 PM
0 Kudos
Message 9 of 14
(6,767 Views)

I'm sorry.  I got Venkatesh mixed up with you.

 

See the attached VI based on what I was talking about to detach the stop condition from the i terminal.

 

Why does the latched mechanical action not work for you?  Are you trying to use local variables elsewhere.

Message 10 of 14
(6,758 Views)