LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting values out of a FOR loop after each iteration.

I'm trying to use a FOR loop to generate a string that has a number in it. I'm polling 485 sensors that are addressed sequentially. So I'm using a FOR loop to control the largest sensor number. It creates a string with a unique address, using the iteration counter, during each iteration. So I need the resulting string of each iteration to come out of the loop when it's generated. Right now all I get is the last iteration. Any ideas?? Thanks in advance.

ssmith490D
0 Kudos
Message 1 of 7
(5,776 Views)
On the string exiting the for loop, right click and select Enable Indexing. This will create an array outside the for loop with the results of each iteration. Indexing is on by default so you would have had to disable it if you're exiting the for loop directly. If you're exiting the for loop via a shift register, then change it so the data exits directly.
0 Kudos
Message 2 of 7
(5,776 Views)
If you need the data items as they are generated at each iteration instead of an array after the For loop is complete, you'll have to write to a local variable or a functional global inside the For loop and read it outside the foor in another part of the diagram that is running. Like a separate While loop.

In all structures, no data is passed out until the structure has completed running, so your only option is to use variables.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 3 of 7
(5,776 Views)
...Or a queue...
0 Kudos
Message 4 of 7
(5,776 Views)
I have it set up with a FOR loop inside a WHILE loop so the polling will be continuous or have some time delay between the instrument polling.I have a local inside the FOR loop, and I monitor it with an indicator, and then a local in between the FOR and the WHILE, also monitored. And still the only value seen in between the loops is the last iteration of the FOR loop. What to do?? ssmith490D
0 Kudos
Message 5 of 7
(5,776 Views)
The local outside the FOR loop (but inside the WHILE) cannot be updated for each iteration of the FOR loop - it's not inside the FOR loop. Highlight execution (light bulb icon in the diagram tool bar) to see what is happening. The FOR loop is executes to completion, then the local variable is updated (or possibly vice versa - again highlight execution to see what's happening and when).

If you are updating the control within the FOR loop, you don't need to do it again in the WHILE loop.

If this doesn't help, try giving more details of what you're trying to accomplish or maybe post your vi.

Tim
0 Kudos
Message 6 of 7
(5,776 Views)
Ed--
Thanks, I got it working. I wasn't using the local vaiables correctly. Thanks for the help.

ssmith490D
0 Kudos
Message 7 of 7
(5,776 Views)