LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger an event with a boolean button only when switching to ON?

Solved!
Go to solution

Hi, I've got an issue with my event structure : I use a boolean On/Off button to launch a state (using producer consummer architecture).

 

When I switch it to ON, my event structure get the "value change" and the appropriate code is executed.

But when I switch it to OFF, the loop in the code is ended, but there is a problem : the event "value change" is activated again, and the code is executed again.

 

How can I avoid it ? there isn't "on" or "off" events in the event structure, only "value change".

 

Here are some screenshots, thanks in advance

 


J.D.
French Labview beginner
N'oubliez pas de complimenter les bonnes réponses - Don't forget Kudos for good answers
0 Kudos
Message 1 of 6
(10,360 Views)

Put your code in the true state of a case structure and wire the ‘New Value’ to the case terminal.

 

Hope this helps.

0 Kudos
Message 2 of 6
(10,341 Views)

Hi, thanks for your answer but it doesn't work, my consummer loop isn't launched because it waits for NewValue


J.D.
French Labview beginner
N'oubliez pas de complimenter les bonnes réponses - Don't forget Kudos for good answers
0 Kudos
Message 3 of 6
(10,336 Views)
Solution
Accepted by JDlabview

J.D.,

 

Use the NewVal terminal in the event case.  That has the value of the control.  If it is True, enqueue the message.  If it is False, do nothing.

 

Generally it is best to have the control terminal in the event case and to send messages to the consumer via queues.  Nested loops like you appear to have can create tricky problems of what is to happen when.  It is unusual for a state machine to need a nested loop which requires operator interaction.  Without the entire VI I really cannot tell what you are doing, but I strongly suspect that there are easier and more robust ways to do it.

 

Lynn

Message 4 of 6
(10,319 Views)

Thanks johnsold, it works !

They are not really nested loops. My VI is made for controlling a spectrum analyser for EMC measurements.

 

I need the hability to begin and start measurement when I want to. I chose to use one button to do both actions, that is why it looks like nested loops.

Maybe it is better tu use one "begin measurement" button to the event structure, and another one called "stop measurement" inside the consumer loop to stop the while loop ?

 

Thanks for your help


J.D.
French Labview beginner
N'oubliez pas de complimenter les bonnes réponses - Don't forget Kudos for good answers
0 Kudos
Message 5 of 6
(10,315 Views)

Whether to use one button or two is a choice you should make based on what works the best for your users.

 

I recommend that any buttons pressed by users to initiate some action by the program be handled by the event structure.  So if you decide to use two buttons, have one event case for the start action and a separate event case for the stop action.  If you use only one button, then the messages enqueued must be different for the True and False values of the button.  Since your Dequeue function is outside the inner loop, it cannot be used to stop the loop.  That is why I was suggesting that the nested loops would be a problem.

 

Lynn

0 Kudos
Message 6 of 6
(10,308 Views)