06-01-2009 01:08 PM - edited 06-01-2009 01:12 PM
I have a situation where i am trying to use occurences to synchronise two while loops. When the 'Threshold' controlvalue is changed, i observe the occurence being set and i think i can see the occurencereaching the second (lower) loop but for some reason the second loop doesn't execute. It gets 'stuck' at the first for loop. I have attached the section of code where my problem occurs (see picture).
Please advise as to what i may be doing wrong, or if there is a better way of initiating/activating the second loop (it only executes once per occurence).
Thank you.
James
06-01-2009 01:49 PM
Its hard to tell but your wait an occurance has no dataflow dependant code after it, essentially all the code in the bottom loop will execute since it is not dependant of the occurance but the loop will block the second itteration until the occurance is set.
06-01-2009 05:47 PM
06-01-2009 10:13 PM
hi james,
I have tried same logic with two while loops.I am attaching my vi for you. I have taken 2 while loops and using occurence tried to run for loop (no event structure).
check if it is helpful to you..if not then please attach your code.
Best of luck
Gaurav k
06-02-2009 03:53 AM - edited 06-02-2009 04:00 AM
Different question - same topic...
With a while loop that is waiting on an occurrence to execute, what's the best way of terminating the loop without running all the code inside it? Actually, even this won't work because if the stop value is changed to false, the whole code in the while loop will execute unwantedly. Any ideas?
Should I set an occurrence when the 'stop' button is pressed, and the enclose all the code in the above-mentioned while loop in a case statement so nothing executes when I'm trying to end the program? ...or is there a better way to achieve this?
06-02-2009 04:26 AM - edited 06-02-2009 04:27 AM
I think i've discovered my problem, (i feel rather silly now).
In my VI, i've got an empty 2D constant wired and indexed into the for loop. This can easily be sorted by using a non-array constant, but it's made me think...
Is there a way of selecting which indexed input of a for loop is the one that controls the number of iterations other than finding the array size of the intended input and wiring that to the count (N) terminal?
06-02-2009 04:30 AM
For several reasons (passing data, error wires), it might be of an advantage to use notifiers instead of occurances. In the 7.1. help there is a note from NI to prefer notifiers...
Felix
06-02-2009 08:54 AM
James Mamakos wrote:In my VI, i've got an empty 2D constant wired and indexed into the for loop. This can easily be sorted by using a non-array constant, but it's made me think...
Is there a way of selecting which indexed input of a for loop is the one that controls the number of iterations other than finding the array size of the intended input and wiring that to the count (N) terminal?
I think you still have some misconceptions. The number of iteration of a FOR loop is determined by the smallest of all following numbers: (1) the value wired to N, (2) the sizes on all autoindexing arrays.
So, if you autoindex on an empty array, you loop will iterate exactly zero times, even if you have a million wired to N.
06-02-2009 09:21 AM
To be honest I have not seen your code but for information, in some cases you can use "Reshape Array" function before passing that array into the loop.
Hope this helps...
06-02-2009 09:47 AM
krsone wrote:To be honest I have not seen your code but for information, in some cases you can use "Reshape Array" function before passing that array into the loop.
krsone,
We cannot tell which post you are replying to and it would be important to know, so always quote a small, but relevant part.
Also the "reshape" answer is a bit too vague: Reshape into what?? 😉