LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Execute event when boolean value changes

Hi everybody,

 

I am trying to control a Pulse Generator with LabVIEW. Sending the commands every iteration of a while loops did already worked out. However, it is unnecessary to send the commands every loop so I want to send the commands only when I change a value at the front panel. Therefore I was trying to use a event structure which worked out very well for all integer values. However, changing a boolean did not lead to the desired event. So far I found out, that I need to switch one "intermediate" toggle in order to switch the desired toggle. Switching the same toggle a few times did not lead to an event. I hope there is a simple solution for this.

I attached an excerpt of my VI.

 

Thanks to everybody who is trying to help!!

0 Kudos
Message 1 of 5
(5,128 Views)

The only change you need to make is to put the Trigger control (on the Block Diagram) inside the "Trigger": Value Change Event.  Did you notice that all of the Square Booleans have mechanical action "Latch when Released"?  This means that their value ("On" or "Off") "sticks" until the control is read.  This is ideal for an Event Loop if the control is inside that Event -- when the Event "fires", the Control is "returned to default state" (i.e. turned Off), ready for the next Push.

 

In your case, you read the Trigger at unspecified, unknown times that have no relationship to the Event Loop.  Who knows what value will be seen?

 

Bob Schor

0 Kudos
Message 2 of 5
(5,116 Views)

First Go HERE and download the instrument driver for that device.

 

Then go here and RTM.  You are not doing what you think you are doing.

 

Several problems exist.  

  • you do not device initialization so the device is in an undefined state when you launch your vi
  • WORSE you have no control of when and in what order buttons get pressed and the state becomes unpredictable very quickly.
  • Making it all even more difficult, you failed to read the values of controls in the event case configured to handle the value change event for that control.  You REALLY want to do that especially with latching booleans.  Maybe you think that that caveat in the help file isn't "really" important.  You are wrong.Smiley Wink

Then we can talk about actually using the instrument driver correctly. 

open session once

Configure

Trigger

Configure

Trigger.....

Close session once.


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 5
(5,100 Views)

Hi Bob_Schor,

 

first of all thank you very much for your help!

I`m sorry but I did not understood where the mistake is. Now I moved all boolean controls on the block diagram inside the respective event but nothing changed. I have still the same problems. As an expample:
When I start the VI and switch the output on, the command is executed. But than, I can switch the output toggle as often as I want, nothing will change, so I will not be able to turn the output off again unless I switch the polarity toggle and than the output toggle again. Now, because I switched the polarity toggle (the command was not exectued) the output at the Pulse Generator is switched off, so the command was executed.

I`m sorry, this is probably a stupid question, but I wasn`t able to figure out how to solve it yet.

Could you please modify the VI or give me a detailed explanation what I have to change?

Marv_92

0 Kudos
Message 4 of 5
(5,096 Views)

Read what Jeff wrote, do what he said (especially about Reading), and think clearly about what you want to do (without worrying too much about how to do it).

 

If you want to explore the "hows", become a Scientist.  Do an Experiment -- write a very tiny VI that has, say, three Boolean Controls, a Push Button, a Stop button, and an OK Button.  Make three indicators -- Pushed?, Stopped?, and OK?.  Drop a While Loop, put in an Event Structure, and make three Events, Push Button Change, Stop Change, and OK Change.  Put the respective control in each Event Case and wire it to its Indicator.  Also wire Stop to the While Loop's Stop indicator.

 

Now run it and play with it.  If things happen too fast, turn on Highlight Execution (the light-bulb, the fifth icon on the Block Diagram Icon bar) and run it again.  Learn.

 

Bob Schor

0 Kudos
Message 5 of 5
(5,085 Views)