LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop inside event structure

I'm prototyping some electronics and temporarily need a while loop inside an event structure in order to run some code within the structure multiple times when the go button is pressed. I know it's poor programming to add a loop inside the structure, but I want to leave it running for a while without user input.

 

At the same time I'd like to be able to break out of the loop and use other buttons inside that event case, but no other controls inside the event structure appear to activate the case, I assume because the structure is associated with the original go button. How can I get around this?

 

 

Thanks 

0 Kudos
Message 1 of 9
(4,270 Views)

grahamwebb wrote:

[...] I know it's poor programming to add a loop inside the structure, [...]


That's not necessarily poor programming. It is if you stack to a depth of more than 5 or 6 (that's the recommended depest nesting).

Nevertheless, you should never use possibly unlimited code execution within an event structure.

 

The solution you are looking for is called Producer/Consumer (Event Based) and can be found in the Template Browser (File >> New).

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 9
(4,261 Views)

Hi!

A similar question has been posted here:

http://forums.ni.com/ni/board/message?board.id=170&message.id=504959

 

Hope this helps,

Marco

0 Kudos
Message 3 of 9
(4,249 Views)

Thanks all, I can see how the producer/consumer with events design pattern would help, but I already have a substantial amount of code in the program to change the structure.

 

Once inside an event is it not possible to escape using user input?

 

 

0 Kudos
Message 4 of 9
(4,235 Views)

Hi graham,

 

you have to enable other user input by setting the actual event to not "block UI events while execution" in the lower area of the event property dialog!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 9
(4,222 Views)

hi! GerdW!

I think that, even if you choose not to lock the front panel,

in order to process the next event the while loop has to be finished.

In the end, IMO, the best choice is be toseparate the user interaction  loop and the elaboration loop.

 

 

0 Kudos
Message 6 of 9
(4,214 Views)

Hi Marco,

 

as I understood that question graham wants to abort a while loop (inside an event case) using a button. To use that button he has to un-block the UI, thus change the event behaviour using the mentioned option!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 9
(4,206 Views)

grahamwebb wrote:

Thanks all, I can see how the producer/consumer with events design pattern would help, but I already have a substantial amount of code in the program to change the structure.



It may be worth your while to implement the solution proposed by Norbert regardless of the fact that youmay have substantial code written already.  Even if you invest a day doing so.  The Producer/Consumer (Event Based) will save you lots of time and grief in the future.  Well worth the investment in time now to do it right.

0 Kudos
Message 8 of 9
(4,204 Views)

I think GerdW has it.

 

I've also set the while loop to continue if true and the push button switches when released, the event is a value change, which seems to do the trick!

 

 

Thank you

0 Kudos
Message 9 of 9
(4,195 Views)