LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event inside "for loop" confusion

Solved!
Go to solution

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

===============================================================

Take a look at DATEx, FOTEx, HELEx & SIGEx add-in trainer boards for NI ELVIS 1,2 & 2+ and DXIQ, ESSB for NI ELVIS III and myDSP for myDAQ to learn Wireless Telecoms, Signals & Systems, Fiber Optics and Green Energy principles (www.emona-tims.com)
0 Kudos
Message 1 of 15
(3,046 Views)

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.

 

0 Kudos
Message 2 of 15
(3,038 Views)

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

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
0 Kudos
Message 3 of 15
(3,022 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 15
(3,020 Views)

 


@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.

Message 5 of 15
(3,002 Views)

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.

 

 

===============================================================

Take a look at DATEx, FOTEx, HELEx & SIGEx add-in trainer boards for NI ELVIS 1,2 & 2+ and DXIQ, ESSB for NI ELVIS III and myDSP for myDAQ to learn Wireless Telecoms, Signals & Systems, Fiber Optics and Green Energy principles (www.emona-tims.com)
0 Kudos
Message 6 of 15
(2,973 Views)

@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".

0 Kudos
Message 7 of 15
(2,964 Views)

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

 

 

 

 

 

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
0 Kudos
Message 8 of 15
(2,958 Views)

OK, here is my current attempt as LV8.6

Previous post is in LV2009.

 

===============================================================

Take a look at DATEx, FOTEx, HELEx & SIGEx add-in trainer boards for NI ELVIS 1,2 & 2+ and DXIQ, ESSB for NI ELVIS III and myDSP for myDAQ to learn Wireless Telecoms, Signals & Systems, Fiber Optics and Green Energy principles (www.emona-tims.com)
0 Kudos
Message 9 of 15
(2,952 Views)
Solution
Accepted by topic author carloman

OK, you are dong things way too complicated.

 

 

  • Use a single event for all boolean mouse downs, then use the ctrlref event output to detect which one. For many more booleans, you might want to use a boolean array instead of all these individual buttons.
  • Don't do the "array to cluster...unbundle" song and dance. That is just silly! "Index array" is sufficient.
  • You need an event for the stop button.
  • Your outer sequence structure has no purpose.
  • The coloring is saved with the VI, no need to recolor with every run.
  • Don't duplicate all that code. Your inner case only differs in a diagram constant, so that's all that belongs inside the case. The "replace array subset" belongs outside.
  • Now simply do the further processing in a new event and ignore if the state is not right. Modify as needed.
Here's a quick draft (LV 9.0) showing some of the suggestions.

 

Download All
Message 10 of 15
(2,936 Views)