05-13-2019 09:37 PM
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.
05-13-2019 09:59 PM
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
05-13-2019 10:25 PM
Thanks for the detailed description. I attached the VI as well. I am a beginner and am studying the properties of loops.
05-14-2019 06:57 AM
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.
05-14-2019 08:38 AM
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.
Bob Schor
05-14-2019 10:11 AM
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.
Bob Schor
I still don't fully understand your solution. But I will learn and implement it on my project and share the update.
05-14-2019 11:57 AM
@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.
Bob Schor
Did you forget about Stall Data Flow,vim?
05-14-2019 12:09 PM
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.
05-15-2019 02:14 AM - edited 05-15-2019 02:17 AM
@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?)
05-21-2019 01:06 PM
Thanks for all the reply.