Showing results for 
Search instead for 
Did you mean: 

Event Handler...hanging vi

Go to solution

Hi , Could someone check what i'm doing wrong please, i have a vi that was running the way i expected with a myDaq picking up two voltages on the ai0 and ai1, i then tried to add an event handler to trigger only when there was a change in voltage ( < 3v).

The issue is when the vi runs it runs once then hangs and not more readings are taken when i have the event handler enabled, if i disable the event handler the vi runs free. Probing on the Event handler i see that the timeout section takes in a value but the aoi section never triggers it seems to do the timeout then wait. I've checked other similar threads and tried adding a shift register to the while loop with vales 0 and -1. I've attached screenshots of the area i think is the issue. All i'm trying to do is trigger when there is a change real time.


any help will be greatly appreciatednoChange.pngTimeout.pngValueChange.png

0 Kudos
Message 1 of 9

truncated diagram pictures are insufficient to troubleshoot your problem. Please attach the actual VI, make sure all controls have typical default values, and tell us how you use it.


Where do you trigger the events, and how?

What is the code architecture (seem you have a case structure inside an event structure inside a while loop inside another while loop). What exactly is the dataflow? Where are the terminals? How are the events configured? Events are primarily for user interactions, not for indicator changes. There are better ways to tell if a value has changed (for example).



0 Kudos
Message 2 of 9

As @altenbach points out, the Event Loop is meant to "catch" Events, most of which are "Did the User change a Front Panel Control?".


This is not your situation.  You are repeatedly acquiring a pair of data points, and are asking "Are these data different from the previous set of data".  


The word "repeatedly" should suggest a While Loop (if "do forever" or "do until I say Stop") or a For Loop (do a known, finite number of times, either a specific N or until you process all the elements of the Array that I brought in through an Indexing Tunnel (the type with a small [] inside the little box).


Inside the Loop, you get the current (or latest) value, and need to compare it with the previous value.  That should suggest a Shift Register.  Put a Shift Register on your Loop.  In this case, you need to initialize the Shift Register by deciding on a reasonable "previous value" when you enter the loop and get the first value (sometimes 0 makes sense, sometimes "minus-infinity", you decide).  Inside the Loop, you can easily compare the "new" to the "old" value and (with a Case statement inside the Loop), do whatever processing is needed for the True case.  You also want to take the "New" value and wire it (before you modify it!) to the right-edge Shift Register so it will be "ready for the next comparison".


Bob Schor

0 Kudos
Message 3 of 9

HI Bob_Schor and altenbach thanks for the replies and guidance , ive tried implementing the the resource you have given but i think im all at sea with the structure and data flow,i'm trying to put to use labview core 1 course into practical use, the daqmx side of things seem ok and i get my readings, but i got this idea in my head of only triggering a warning when the voltage state has changed. I have attached a Light detecting circuit and only want a sound when the state has changed above 3 V and then if it dips below 3V then the sound will come on again.


Ive implemented the shift registers to check the values between old and new, an issue here is that the first reading could be wrong depending on the state of the light circuit.


Ive tried running the while loop once by adding in logic to reset the while loop, this doesnt work.


Implemented what altenbach suggested by adding in the is value changed vi and then adding in another case structure to trigger , so i thought if the states changed but it only seems to work on true.


Just a few lines to say that i am trying what you say to gaet this working



Download All
0 Kudos
Message 4 of 9

Hi , ive taken it back a bit until i get my head round the logic , still cant get it to trigger once until the voltage changes again ....

0 Kudos
Message 5 of 9

@Chizzy42 wrote:

Hi , ive taken it back a bit until i get my head round the logic , still cant get it to trigger once until the voltage changes again ....

That code is just way too confusing. You have LEDs  with "on" or "off" in the name but they can be either on or off.

What is the point of the two index controls? Should the user really be able to change those?


What is "it" that you want to trigger? Can't find it.(sic). 😄


0 Kudos
Message 6 of 9

Hi, what im trying to do is

1.Measure two ldr circuits i have connected to a NI myDaq in a differential setup on ai0 and ai1

2 When the voltage is above approx 2.5V then labview code would acknowledge this and make a sound only once to announce this change.

3. It would only change when the voltage dropped below the off threshold which is approx 1.5V(i was just trying the limits out on labview as one of the modules reads a bit lower).


the last one with the boolean on the front panel just reacts when the voltage from the myDaq is above or below the set voltages . Im trying to put into practice what i've been doing on the courses in making a working project.

The index controls just let me get the data from ai0 and ai1, im not sure this is the most practical way of doing (since you've mentioned it, i guess not) 


thanks for looking

0 Kudos
Message 7 of 9
Accepted by topic author Chizzy42

I can't see your code (I have LabVIEW 2019 and 2021, nothing newer).  I made the following demo that doesn't use DAQmx or fancy codes, just a Signal (I used a Boolean Push Button which can be On or Off) and "sample" it without DAQmx (I read its value).  I do use one "trick" -- I know LabVIEW stores Booleans as 0 and 1, with 0 being False and 1 being True.  So if I "compare" two Booleans using "Greater Than", it will be True only when the top input (which is the Signal) is 1 and the lower input (which is the previous value, from the Shift Register) is 0, i.e. on a Rising Edge.  I'll let you figure out how the Falling Edge works (but it does ...).


Note that I'm "sampling" at 2 Hz, so don't go mashing that Signal button too fast.  I used a slow speed so you could see the Rising and Falling Edges clearly.


This is the simple logic of Rising and Falling Edges.  It is Rising when New > Old.  All you need are New and Old and a comparator.  

Rising and Falling Edges.png


Note also that I used Booleans, which take on only 2 values.  What if you are using "Analog" data, like voltages?  What does a Rising Edge mean?  Look up how TTL signals are defined.  I'm not an engineer, so don't know the exact values, but "if the voltage is near 0 V, it's Off, and if near +5 V, it's On".  So what does "near" mean?  How about "within, say 1.5 V"?  Now there are two "comparisons" to make, and three "logical" states to consider.  If the voltage is < 1.5 V, it's Low, if >3.5 V, it's High, and if between 1.5 and 3.5, it is "whatever it was the previous time".


Bob Schor

Message 8 of 9

Hi Bob Schor ,thanks for the example that's what i was looking for and explaining it very badly to you both, it was a latch that didn't change until the next change occurred i was trying to do. I can get on now with trying other ideas from the core course with the myDaq.


Thanks again for your and altenbach's time and patience for guiding me to this, much appreciated. 



0 Kudos
Message 9 of 9