LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass on each output value of FOR loop onto a case structure ?

Hi,

 

I am using a for loop to generate some numbers each of which I want to be an input for another block of code. However, while executing, only the value from the final iteration step is getting passed on. I would be glad to know about ways of fixing this problem. Thanks.

0 Kudos
Message 1 of 11
(3,298 Views)

I don't look at pictures of code.  Post your VI.  But even without looking at it, I can tell that you don't understand For loops, don't understand that if you bring a wire representing, say, an I32 (integer) quantity, by default the output tunnel turns into an "indexing Tunnel", which makes the output an array of I32.

 

And inside the For Loop, you have the various values present one at a time, so you can do anything you want to  with them inside the For Loop.

 

So you have a choice -- Put your processing of a single element inside the loop and process the generated values one at a time, or bring the elements out through an indexing tunnel and process them all outside.  But how, you ask, do you process the elements of an Array one at a time?  Have you learned about For loops?  [For loops?  Weren't we talking above about For loops?  Why are we talking about For loops again?]

 

If you bring an Array (the Wire looks like a thicker version of the correponding Scalar wire) into a For loop, the input tunnel, by default, turns into another indexing tunnel.  On the output (right) side of the For Loop, the Indexing tunnel turns scalars into Arrays -- guess what it does on the input (left) side -- it turns Arrays into the corresponding Scalar, looping once for every element in the Array.  And you don't have to (and shouldn't) wire the "N" terminal -- it will automatically loop once for every Array Element.

 

Now, had you posted your code, I might have modified it into some examples, but I try to avoid looking at pictures.

 

Bob Schor

Message 2 of 11
(3,286 Views)

Thanks for the detailed description. I attached the VI as well. I am a beginner and am studying the properties of loops. 

0 Kudos
Message 3 of 11
(3,278 Views)

Here's a better version. I moved the writes inside the loop, reformatted the data so that everything is left to right and is less Rube-Goldberg (this could probably still be improved upon), and got rid of the stacked sequence. Moving inside the loop makes it work on each of the wavelengths. If you need time between wavelengths then add another wait in a frame at the end of the flat sequence.

Message 4 of 11
(3,254 Views)

Get rid of the Frame Sequence!  You might need a single Frame to surround the Wait if you need to put it between the two Send GPIB commands, as opposed to setting the overall rate of the loop (in which case you don't need the Frame at all).  I also wired the Error Lines (they are there for a reason!) and straightened out the wires -- now you can almost see what's being done.

1835 Config1835 Config

Bob Schor

0 Kudos
Message 5 of 11
(3,240 Views)

Thanks for the much detailed and informative response. 


@Bob_Schor wrote:

Get rid of the Frame Sequence!  You might need a single Frame to surround the Wait if you need to put it between the two Send GPIB commands, as opposed to setting the overall rate of the loop (in which case you don't need the Frame at all).  I also wired the Error Lines (they are there for a reason!) and straightened out the wires -- now you can almost see what's being done.

1835 Config1835 Config

Bob Schor



I still don't fully understand your solution. But I will learn and implement it on my project and share the update.

0 Kudos
Message 6 of 11
(3,227 Views)

@Bob_Schor wrote:

Get rid of the Frame Sequence!  You might need a single Frame to surround the Wait if you need to put it between the two Send GPIB commands, as opposed to setting the overall rate of the loop (in which case you don't need the Frame at all).  I also wired the Error Lines (they are there for a reason!) and straightened out the wires -- now you can almost see what's being done.

1835 Config1835 Config

Bob Schor


Did you forget about Stall Data Flow,vim?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 7 of 11
(3,220 Views)

Virtually none of the controls belong inside the loop, because the operator should not be able to modify these values within 250ms resolution. Most code belong before the loop, except a simple formatting statement for the wavelength.

0 Kudos
Message 8 of 11
(3,215 Views)

@altenbach wrote:

Virtually none of the controls belong inside the loop, 


... here's how that could look like ... (Note that there is no delay between the "write" on the left and the "write" from the previous iteration. Maybe you need on there too. Not shown. Also note that the first wavelength is never sent, only the first + 20nm. Is that as designed?)

 

1835.png

Message 9 of 11
(3,186 Views)

Thanks for all the reply. 

0 Kudos
Message 10 of 11
(3,075 Views)