LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event isn't timing out until external for loop finishes

In my code I have a for loop that is external to an event structure. This for loop is driven by a button press from one of those events. This for loop will take 6 seconds to execute all of its states because I designed it that way. I would like the user to be able to cancel this for loop with a stop button. My thoughts were to create another event, feed the stop button output into a condition terminal on the for loop.

The problem I am running into is the event structure will not timeout until the for loop is completed, even though it is external. I set the timeout to 100 ms. There is data leaving the for loop in a queue but other then that nothing leaving the for loop. Any thoughts?

0 Kudos
Message 1 of 11
(3,544 Views)

I suspect a mis-understanding to how the Event structure works but it is hard to tell what you mean by "external". Can you share your code? Or at least a screenshot.

0 Kudos
Message 2 of 11
(3,542 Views)

I can provide one tomorrow but in the meantime let me try to explain. By external for loop I mean one that is not nested inside the event structure. My understanding of events is that they are like interrupts in C. They can be used instead of polling but its not a great idea to do a lot of computation inside.

0 Kudos
Message 3 of 11
(3,529 Views)

@MicahKurtz wrote:

I can provide one tomorrow but in the meantime let me try to explain. By external for loop I mean one that is not nested inside the event structure. My understanding of events is that they are like interrupts in C. They can be used instead of polling but its not a great idea to do a lot of computation inside.


Conceptually yes, but the better way to think of them is a structure that generates a event queue for future processing and registers this to the UI loop. When an event occurs (asynchronously) then this is added to the queue. When the event structure executes, it dequeues the next event off the list and processes it. This is why event structures are typically housed within loops in order to enable processing a new event off the list on the next iteration.

0 Kudos
Message 4 of 11
(3,523 Views)

Ok that makes sense. So possibly whats happening is the event that is driving the for loop does not finish executing until the for loop does. I don't understand why this would be. I was expecting the event structure to timeout and just wait for the next event, meanwhile the for loop just does whatever it wants without bothering the event structure.

0 Kudos
Message 5 of 11
(3,520 Views)

When you post an example of what you have we will be able to give you a better answer.

0 Kudos
Message 6 of 11
(3,505 Views)

@MicahKurtz wrote:

Ok that makes sense. So possibly whats happening is the event that is driving the for loop does not finish executing until the for loop does. I don't understand why this would be. I was expecting the event structure to timeout and just wait for the next event, meanwhile the for loop just does whatever it wants without bothering the event structure.


It is sounding like you have an Event Structure and the FOR loop inside of a WHILE loop.  The while loop cannot iterate until everything inside completes.  So the Event Structure will not be executed until the loop iterates, which cannot happen until the FOR loop completes.

 

Again, we can explain better when you provide an example.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 11
(3,482 Views)

Yes, I think that is whats happening. Both are inside a while loop. Tomorrow I can post a screen shot. Can't post the VI because of my companies IP rules.

0 Kudos
Message 8 of 11
(3,437 Views)

Here are two screen shots. One is of the button inside the event structure called 'Run Full Test' which causes the VI 'Run Full Test' to run. The other screen shot is inside 'Run Full Test' and shows my attempt to stop the for loop.

 

What I've tried is creating a reference from the stop button inside the for loop to a stop button on the front panel. This won't work because once the button 'Run Full Test' is pressed there is a very short window of time the user has to press the stop button (which isn't labeled in the screen shot, but it the Boolean) because the for loop is entered. I am not sure how to get around this.

 

It seems like the best solution is to put the VI running the for loop inside the event structure, but I understand loops in event structures are bad ideas. I can't think of another way.

Download All
0 Kudos
Message 9 of 11
(3,421 Views)

MicahKurtz wrote:

It seems like the best solution is to put the VI running the for loop inside the event structure, but I understand loops in event structures are bad ideas. I can't think of another way.


You should do this if the VI is "quick".  If it isn't, you should move it into a completely different loop with a Queued Message Handler, Actor, or etc.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 11
(3,411 Views)