03-21-2011 07:33 AM
Hello all,
I have an event inside an N=2 for loop, which outputs a 2 element array (auto-index mode). The first value is from a first event, the second from the second event. Events are mouse clicks on a front panel control with many buttons.
Am I able to access the i counter inside the for loop prior to the 2 element array being output ? It seems not.
Perhaps as I just want 2 events in sequence I should put two copies of this event in a 2 frame sequence...but this creates the need for setting up the event twice...a hassle, as it contains many possible sources.
Ive tried while loops, passing i as a local variable, tunnels, shift registers...but I dont seem to be able to access i during the looping.
Can someone suggest a way, or a better approach/structure for this issue.
In any case, it seems the program is locked up waiting for the second event, so I cant do anything with the value anyway ?
I would like to take some action after the first event and before I await the second event.
Thanks,
carloman
Solved! Go to Solution.
03-21-2011 07:47 AM
Can u plz post ur VI in 8.6 version. Where u want to use i? INside event structure or in the for loop?
More details required.
03-21-2011 08:38 AM
following the dataflow model of LabVIEW, you can not access the output of the FOR-LOOP prior to when it's finished.
So as long you're in the for-loop you can access the "i" terminal. or you're doing something wrong 😉
As already indicated, please post your VI so we can have a look at it, and give you some assistance
03-21-2011 08:40 AM
What is the issue you are experiencing? You aren't giving a clear explanation of what is or is not working. Also, posting the code would go a long way in being able to help you.
03-21-2011 10:46 AM
@carloman wrote:
...
I have an event inside an N=2 for loop, which outputs a 2 element array (auto-index mode). The first value is from a first event, the second from the second event. Events are mouse clicks on a front panel control with many buttons.
Am I able to access the i counter inside the for loop prior to the 2 element array being output ? It seems not.
Perhaps as I just want 2 events in sequence I should put two copies of this event in a 2 frame sequence...but this creates the need for setting up the event twice...a hassle, as it contains many possible sources.
Yes, post your code. Your description sounds like a nightmare!
Even structures should never be used like that. Event structures always queue up events, even if dataflow prevents them from reacting. For example, if the operator clicks on that control 100x before the FOR loop is in the dataflow, results will be quite unexpected. By default, the front panel will be locked until the event completes, locking the program forever. Placing two event structures in sequence is even worse.
Typically, a single event structure is used in a toplevel while loop. Build your two points in a shift register and use a nice state machine that switches state once two elements are present.
03-22-2011 06:28 AM
OK...sorry about the lousy description.
Anyhow, thanks altenbach for your suggestions.
Here is my attempt at code to do what I want.It still has numerous problems
My aim is:
1) Users click on any LED, and it lights up, under program control, and value from event is stored in output array.I dont need it yet.
2) on second click of any LED (same or other), I want them ALL to switch off, and value from 2nd event to be added to the output array, and then this 2 element array is output for further processing. (I then draw lines between the selected LEDS etc later on in this same loop..that part working OK)
3)then back to (1) for another pair of selected LEDS, until STOP.
Im using LEDS as they look good and are easy to turn on & off directly with boolean data.My final code will have about 80 LEDS,so I need it to be easily scalable.
Current problems are:
-the 2 element array is not output after the 2nd click...hence disrupting my drawing code.Earlier I had the array being output via an auto-indexed terminal in the for loop.
-the stop does not respond...I guess the event is running still .
-i use state as a gate signal, which seems rather clunky, and requires a null element in the boolean array.
Any more suggestions much appreciated...especially how to structure this so I get my 2 element array output in 1 burst.
Thanks.
03-22-2011 07:11 AM
@kekin wrote:
Can u plz post ur VI in 8.6 version. Where u want to use i? INside event structure or in the for loop?
More details required.
I hope we're not going to start polluting the forums with this "textese".
03-22-2011 07:17 AM - edited 03-22-2011 07:20 AM
put it in a state machine.
Add a shift register with the value you wish to keep (array)
In the idle state you will have a event structure which checks the buttons or LED's as you call them.
On event of the buttons (LEDs) :
- if the array is empty => add (cause it's your first event) and stay in idle state
- if there is already an items in there => add the second one ; clear LED's and go to process state of state machine => then back to idle
On event stop => stop state engine
03-22-2011 07:20 AM
OK, here is my current attempt as LV8.6
Previous post is in LV2009.
03-22-2011 08:21 AM - edited 03-22-2011 08:23 AM
OK, you are dong things way too complicated.