LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to force stopping a FOR loop in an EVENT loop (or how to interrupt an event)

Solved!
Go to solution

Hello,

I have a certainly very common problem, which is that I use FOR loops in an event structure, and a long process starts when entering the FOR loops. I would like to be able to manually stop the FOR loop (via a "stop for loop" button) and therefore finish the event execution faster (in case, for instance, I realize I set wrong parameters before running the execution of the event). I attached a basic example as my real code is used for controlling light sources, cameras, stage motors etc and is far too complicated).

I am sure the problem comes from bad programming and that a for or while loop should never occur in an event loop. I would therefore much appreciate if you could either give me an option to solve my problem in my current azrchitecture, or if you could suggest another architecture. Note that my real Event stucture contains much more event cases, and that the Time Out event isn't empty. Note also that I only have Labview 2017 and won't be able to open exemples generated with newer versions. thank you in advance for your help ! Best regards. 

0 Kudos
Message 1 of 5
(1,050 Views)
Solution
Accepted by topic author sophiebiovision

Hi Sophie,

 


@sophiebiovision wrote:

I have a certainly very common problem, which is that I use FOR loops in an event structure, and a long process starts when entering the FOR loops. 


This problem is only common to LabVIEW beginners…

There is a LabVIEW help for the event structure. In this article is a link to "Caveats of the event structure", which is important to read!

 

Solution:

  • Don't place the FOR loop inside the event case.
  • Don't have code inside an event case, which takes more than a few milliseconds to execute!
  • Don't block (other) event handling by code execution within the event case!

Btw.

  • Don't use local variables when a shift register does the same…
  • Don't maximize window size to screen, especially for such tiny code.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(1,032 Views)

after sendin my post I found that when going to Edit events and unclicking Lock Panel for the "start" event then my stop loop button becomes active !

That will suit me I think, but don't hesitate and propose other option if you think this one isn't proper. I suppose it might be dangerous as any accidental action on the front panel might cause to stop the event when I don't want it to be stopped. anyway, Ill work with this solution for the moment.

Best

0 Kudos
Message 3 of 5
(1,029 Views)

@sophiebiovision wrote:

after sendin my post I found that when going to Edit events and unclicking Lock Panel for the "start" event then my stop loop button becomes active !

That will suit me I think, but don't hesitate and propose other option if you think this one isn't proper. I suppose it might be dangerous as any accidental action on the front panel might cause to stop the event when I don't want it to be stopped. anyway, Ill work with this solution for the moment.

Best


Oh, no - the "Great Lock the Front Panel Debate!"  In a nutshell, though, while it has it's very specific uses, I generally don't advocate for its use, as it encourages bad habits, and if abused without understanding - as it seems in your case - could lead to confusing and unintended consequences.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 5
(992 Views)

In addition to what has been said already.

 

  • None of your init code in the timeout is needed. Just make all buttons latch action and place their terminal inside the structure where they get read. 
  • There is no reason to have these inner loops. You can use the outer while loop and some integers in shift registers do do exactly the same actions.
  • You are dealing with integers. There should be nothing orange.
0 Kudos
Message 5 of 5
(970 Views)