LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop loop inside an event

Solved!
Go to solution

Hello,

 

I'm trying to stop a loop inside an event. The attached Vi is a very simplyfied version of a project im working on, but the structure is the same. It's basically a state machine with one state for initializing, one for exiting and one that contains an event structure and waits for events. I can't figure out how to stop a loop, that's inside an event, while the event is active. I tried creating a seperate event, that closes the programm, but while the Event im trying to stop is active, none of the buttons on the front panel can be clicked. I basically want one button, that when clicked, stops any loop in any event and then closes the program, by activating the event Exit.
I hope I made my problem as clear as possible.

 

Help you very much in Advance!

 

Greetings

 

Paul

Download All
0 Kudos
Message 1 of 10
(1,770 Views)

Every event case has the option to lock the FP until the event processing completes. This option is on by default. You may set this option off; this will alllow polling a stop button during the cycle, however you must disable all controls that you don't manage in the event case and re-enable them when done.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 10
(1,734 Views)
Solution
Accepted by topic author pfigueroa

Untag the "Lock Panel" option of the event case might do the trick. That might still not work if the controls have events attached to them (not sure).

 

It will be a bandage at best, a quick fix, a hack...

 

You usually shouldn't have long loops in an event structure to begin with. Either start a dynamic VI to do the task, or use events, queues, channel wires, whatever to perform the task in a parallel loop.

 

Ever wandered about all those posts about architecture (Actor Framework, DQMH, Producer\Consumer, etc.)? You probably need to step up your architecture now or soon. You can only do so much in a single loop before it blows.

0 Kudos
Message 3 of 10
(1,732 Views)

wiebe@CARYA wrote:

Untag the "Lock Panel" option of the event case might do the trick. That might still not work if the controls have events attached to them (not sure).

 

It will be a bandage at best, a quick fix, a hack...

 

You usually shouldn't have long loops in an event structure to begin with. Either start a dynamic VI to do the task, or use events, queues, channel wires, whatever to perform the task in a parallel loop.

 

Ever wandered about all those posts about architecture (Actor Framework, DQMH, Producer\Consumer, etc.)? You probably need to step up your architecture now or soon. You can only do so much in a single loop before it blows.


You should definitely consider a better architecture. The bandage might appear to fix your immediate problem, but you are still unable to respond to any other front panel activity as long as you are in the loop. I rarely have an application that doesn't use at least two loops, and often more than that (user interface, data acquisition, Instrument Control, Data processing, Data logging, as just a few examples).

0 Kudos
Message 4 of 10
(1,710 Views)

Hi pincpanter,

 

thank you for your quick response!
I did what you said and disabled the lock Panel Option, which allowed me to click on the stop Buttons to stop each individual while loop. However if I click the Exit button it only triggers the Exit Event after the while loops in the first Event are stopped. That's not a very good solution since I want one single button to be able to Abort any activity in any Event.

0 Kudos
Message 5 of 10
(1,695 Views)

@pfigueroa wrote:
I did what you said and disabled the lock Panel Option, which allowed me to click on the stop Buttons to stop each individual while loop. However if I click the Exit button it only triggers the Exit Event after the while loops in the first Event are stopped. That's not a very good solution since I want one single button to be able to Abort any activity in any Event.

That's how dataflow works.

 

The event structure won't proceed to the next case until it's current case is done. There's no way to make it execute two event cases at the same time.

 

The event structure is (by design) not a structure that executes cases when events happen. It executes the first event that it on the event queue, or waits until there is an event. Only then it processes the next event.

 

If two events would be processed simultaneously, how would shift registers work? This would be completely different from the wireflow model that is the biggest pillar of LabVIEW.

 

You should make an architecture that executes long tasks in parallel, so the event structure can respond to incoming events.

0 Kudos
Message 6 of 10
(1,687 Views)

Hello,

 

thank you very much for your advice. I went on and put the while loops inside an individual state of the case structure and left only the Buttons inside the Event case to trigger the states. Also I used a global variable to read in the value of the Abort butto, which then stops the while loops and triggers the Exit Event. For this I didn't have to disable the lock panel Option. I'm sure this is not the best way to do it, but it works. I would however be happy to hear about a more elegant way to solve this. I'm also fairly new to LabVIEW and still in the learning process, so I havent had the Chance to up my game in Terms of Architecture.

Download All
0 Kudos
Message 7 of 10
(1,683 Views)

Yes, I'm aware of the wireflow model, I just needed a way to stop the running Event, so that the next one (Exit Event) could be excecuted. I managed to do that in some way with a global varible and channel wires.

 

Thank you very much for your advice!

 

Greetings

 

Paul

0 Kudos
Message 8 of 10
(1,679 Views)

@pfigueroa wrote:

Hello,

 

thank you very much for your advice. I went on and put the while loops inside an individual state of the case structure and left only the Buttons inside the Event case to trigger the states. Also I used a global variable to read in the value of the Abort butto, which then stops the while loops and triggers the Exit Event. For this I didn't have to disable the lock panel Option. I'm sure this is not the best way to do it, but it works. I would however be happy to hear about a more elegant way to solve this. I'm also fairly new to LabVIEW and still in the learning process, so I havent had the Chance to up my game in Terms of Architecture.


The way you did this now, is not too far away from a producer\consumer 'architecture'.

 

It's more a pattern than an architecture, as it's simply a way to build one VI. Architectures as I see it, involve more complex relations and communication between multiple VIs.

 

If you press New... Then under VI open the "From Template" subtree, you should see the Producer/Consumer Design Pattern (Events).

 

I don't think you should need much time to relate that pattern with what you're doing. You could probably copy paste the upper loop into your VI, and then replace the P/C event structure with yours. Then do the same for the lower loop. It will need some stitching, but it won't require a complete rewrite.

Message 9 of 10
(1,667 Views)

With just a little work you can get rid of the need for the global variables (local variables would be just as good in the way that you're doing this, and no need for the extra loop in that case). Think of your two For loops as states in your state machine. Repeat state 1 until number of cycles is reached or Abort is pressed. The same with the second loop. 

0 Kudos
Message 10 of 10
(1,659 Views)