01-28-2009 02:53 PM
My question is how to check if the for loop finished? I am controlling a Lambda Genesys supply and taking a linearity data. I need to check if the loop finished, ask the user to reverse the polarity and take data again. Got only the first portion to work. Looks like I can't just check the loop iteration to be the last.
I attached my code for anybody to check if possible.
Thanks for your help.
Peter
Solved! Go to Solution.
01-28-2009 03:38 PM
I think I figured it out. I am attaching a copy of my code. Can anybody tell me if there is an easier way to acomplish my task?
Thanks again for your input.
Peter
01-28-2009 03:49 PM
There are a couple of things you can do to make your code simpler. First of all, remove the sequence structure. Use the Error In and Error Out terminals to chain together your VIs in the order in which you want them to execute, as you're already doing in one of the sequence frames.
For Loops in LabVIEW have a neat auto-indexing property. You can pass in an array and it will execute once for each element of the array. So, you can move your build array outside the for loop, remove Index Array, and connect a wire directly from the array into the For Loop. When you do this you do not need to wire the "N" terminal; the loop will execute as many times as there are array elements. You might want to use an array constant instead of a bunch of numeric constants combined with build array, but that's just a matter of style; LabVIEW will treat them identically.
Finally, you don't need to multiply by 1 in the second frame of the sequence structure.
01-28-2009 04:22 PM
Piotrekp wrote:I think I figured it out. I am attaching a copy of my code. Can anybody tell me if there is an easier way to acomplish my task?
Natahnd already commented on your first attempt. Looking at your second attempt, you still have twice as much code as needed, because the bulk of the code is duplicated into two instances. This doubles the chances of accidental errors and every time you need to make changes, you need to make identical changes in two different places. This is a code maintenance nightmare! You could just place another FOR loop with a 2 wired to N around the code, display the conditional terminal, and exit the loop prematurely depending on the outcome of the dialog box.
01-28-2009 04:32 PM - edited 01-28-2009 04:34 PM
altenbach wrote: You could just place another FOR loop with a 2 wired to N around the code, display the conditional terminal, and exit the loop prematurely depending on the outcome of the dialog box.
Here's a quick draft, modify as needed. (There are a few loose ends, e.g. you should enable the message only on iteration 0. Easy to fix. ;))

(I don't have DAQ or even understand your hardware, so I cannot test, but things don't quite look right overall.
01-29-2009 09:41 AM
I wanted to thank you guys for your help and advice. The program works great.
Peter