07-01-2010 06:54 AM - edited 07-01-2010 06:56 AM
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
Solved! Go to Solution.
07-01-2010 07:36 AM
Put your code in the true state of a case structure and wire the ‘New Value’ to the case terminal.
Hope this helps.
07-01-2010 07:55 AM - edited 07-01-2010 07:56 AM
Hi, thanks for your answer but it doesn't work, my consummer loop isn't launched because it waits for NewValue
07-01-2010 08:15 AM
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
07-01-2010 08:36 AM
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
07-01-2010 09:40 AM
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