LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

setting a single button to do a task in different loops

I have two separate while loops and I want a single button to perform the same task in both loops. Is there a way to configure this or am I stuck with having 2 buttons?
0 Kudos
Message 1 of 6
(3,051 Views)
This is usually not too much of a problem. You can create a local variable from the button and use that to read in one of the loops. You will not be able to use the mechanical action "Latch when..." for the button, but have to change it to "Switch when...". This also means that one of the loops will probably have to turn the button off again. It's a little more programming, but it works.

For another method you could use a notifier (or an occurance, but I'm not fond of those) for one loop to "tell" the other loop that the button has been pressed.

Rob
Message 2 of 6
(3,051 Views)
Hi Rob, thanks for the reply,

My program requires the button to have the "Latch until released" property, so I was wondering if you could tell me a little more about using a notifier

Thanks,

Dogbert
0 Kudos
Message 3 of 6
(3,051 Views)
Notifiers are named so you can set them up in 2 different VIs or in 2 different loops (in this case). You create a notifier and then you can send a notification (which can be any type of data) or you can wait for a notification. You can also use the VI for "Check Notification Status" that will check for the notifier without stopping the loop to wait for the notifier (your other processes can keep running).

I've built a quick little VI to show notification between 2 loops. The first loop waits for the button press and the second loop waits for notification from the first. Hopefully, this will answer your questions.

Rob
0 Kudos
Message 4 of 6
(3,051 Views)
> My program requires the button to have the "Latch until released"
> property, so I was wondering if you could tell me a little more about
> using a notifier
>

The deal is that the latch behavior is defined to reset the button when
it is read. The problem is that when more than one location on the
diagram reads the button, when does it reset? It could reset on the
first read, but that isn't what you want as only one loop would see it.
It could reset on a particular read, it could reset after all of the
places have read it, but what if one of the loops reads it N times
before the other loop reads it? To "fix" this, LV requires you, the
programmer to determine what behavior you want and reset the button
yourself using a write
local variable. If you know how your loops run,
or if they are synchronized, you can choose one to read and the other to
read and reset. Be careful here that you don't write a program that
drops the button and doesn't let one loop see it.

The other suggestion was to use a notifier. This means that the button
belongs to one loop, and is read and latched by that loop. The other
loop instead reads from a notifier object in LV. The loop that owns the
button sets the notifier when it sees the button toggle. The notifiers
are located in the Advanced/Synchronization palette, and there are some
examples of their use in the examples/general/notifier.llb, but they may
not help that much. You might be better off just reading about them in
the manual.

Greg McKaskle
0 Kudos
Message 5 of 6
(3,051 Views)
Notifiers are ideal for this situation. If your two loops don't necessarily run simultaneously (or fast enough), you might want to make a third loop just for the purpose of reading the button and sending the notification each time it is clicked.

One thing you'll have to think about is each time you wait on the notifier, whether you should ignore previous notifications or not. The manual will make it clear what the implications of this are.
0 Kudos
Message 6 of 6
(3,051 Views)