Pedro77
Pedro77

Reputation: 5294

Labview events - do a taks in parallel to a running loop

I'm trying to do something very simple:

enter image description here

Option 1 - Loop outside event enter image description here

Option 2 - Loop inside event enter image description here

I just want to be able to keep the loop running and the OK button working at the same time, how can achieve that simple task in Labview "way of life".

Results:

Upvotes: 0

Views: 1760

Answers (4)

D.J. Klomp
D.J. Klomp

Reputation: 2669

Here is how you can do it with a Master/Slave configuration. All the user events are handled in the master, the counting is handled in the slave. The loop can be restarted and the stop works for both loops.

The main code to run

To Stop the code you use a different event, in the case the loop conditional is false you don't do anything in the slave loop. Not shown here, but the loop conditional also has it's own event structure to reset the counter if needed.

The stopping condition

This master/slave structure is extendable to as many loops as you want.

Upvotes: 1

D.J. Klomp
D.J. Klomp

Reputation: 2669

I think the design pattern you are looking for is the Producer/Consumer pattern. This allows you to run parallel loops and if need be share data between them.

A quick google on the term combined with labview will give you enough examples.

Upvotes: 0

RomCoo
RomCoo

Reputation: 1893

I see two options:

  1. Similiar to option 2 but do the "loop math" not inside the "Loop Value Canged"-Case but inside the "Timeout"-Case. Then you don't need the while loop, use a if-case (loop = true) instead.
  2. Use two while loops. Inside each of them put a event case. One to handle the "C=A+B"-Event and one for the "Loop Value Changed".

Upvotes: 0

Ton Plomp
Ton Plomp

Reputation: 3105

You can't. You'll need two seperate while loops, one with the count functionality, but don't use the 'loop' variable as the stop condition, make the loop variable control a the count condition. In the other while loop you'll have your event code. The only thing you'll have to worry about is stopping the first while loop from the event code.

Upvotes: 2

Related Questions