LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically detect a value change event

Hello,

 

I've been trying to figure this out for a few days now, and I'm not sure what the best way to go about doing this is.

 

I would like to detect a programatic change on an indicator and have that trigger an event.

 

I've been trying to use the "value Signaling" property to do this, but I can't have it in the while loop cause it fires an event case on every iteration of the while loop (and I essentially get stuck in the event case)

 

What I've come up with so far is sending my indicator value through a shift register and comparing the previous value to it's present value, and if it's not the same I write to the value signaling property and fire the event case... but doing it this way to me almost defeats the purpose of an event case, cause I'm basically polling my indicator (and hence might be liable to miss a value change) and then executing some code if I see a value change...

 

can anyone point me at a better way of doing this... I see something called user defined events and I'm in the process of reading about these but I don't know if it's the right path

 

much thanks!

 

My code (that works but defeats the purpose of an event case)

 

ValueSignaledEvent.JPG

Message 1 of 21
(13,858 Views)

Do I understand correctly, that the control 'x' would be an indicator you update from/inside another section of your code and want your event structure fire whenever this changes? This assumes you are also using a multiple-loop architecture.

 

I see two basic options:

1. You do not directly update your indicator 'x' via the terminal but via a property node with value(signaling). I'm not sure if this would always fire an event, if so, you can just compare 'Old value' and 'New value' in your event frame.

 

2. Instead of directly updating your indicator, you fire a User Event. Updating the indicator via the terminal would happen inside the event frame. Same isssue about 'did it really change the value' is here for certain.

 

To both cases, you can always just do not fire the event as you do in your example in the indicators update section of your code.

 

Felix

0 Kudos
Message 2 of 21
(13,850 Views)

Thanks for the reply, yes the control 'x' would be an indicator that gets updated by another section of code, not from a multiple loop architecture though just from a DAQ module that's reading in a voltage, but the voltage will not be changing that often.

 

comments on your options:

1.  That's almost what I'm showing here, I'm updating my indicator property node value(signaling) and then carrying out  myt code in the event, but unfortunately value(signaling) fires on every iteration of the while loop, to avoid this I'm comparing the old and new values of my indicator and only writing to value(signaling) if I see a change.... but to me this defeats the whole purpose of having an event... I might as well put my code in the case where value(signaling) is and it would have the same effect

 

2. I'm still trying to figure out what these User Events are and if they would be able to help in this problem.... I'm not clear on how they work yet.

 

much thanks!

0 Kudos
Message 3 of 21
(13,844 Views)

I might as well put my code in the case where value(signaling) is and it would have the same effect

 

If so, then what would be the reason to put the code in the event structure?

 

Felix

0 Kudos
Message 4 of 21
(13,839 Views)

 

 

 

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 5 of 21
(13,820 Views)

 



 

Thanks for the reply, yes the control 'x' would be an indicator that gets updated by another section of code, not from a multiple loop architecture though just from a DAQ module that's reading in a voltage, but the voltage will not be changing that often.

 


 

If you only have 1 loop and in that loop you are reading a value from some hardware then you have to be constantly polling to get this value, in that case it seems pointless to have the Event structure in that same loop? Like Schubert i assumed that you had multiple loops and that you was struggling passing the value from a 'Daq Loop' to your 'Event structure Loop', something like:

 

User Event Example 1.png

 

If you have a loop with lots of events captured by an event structure and you simply want to send the value of a reading from your hardware to that loop then the above will do that. If you are reading from an external piece of hardware then you will have to have at least 1 loop polling the hardware. If you have the same logic that calculates whether it is a new value then fires an event in the case structure then you might as well have the event case logic in that case structure? I dont know if i am missing something here.

 

I will attach the above example just in case this could be something you could use. In the bottom loop i have used an 'Approx Equal' vi i wrote. It is well documented on this forum the perils of using equals function to compare doubles. With this vi you can set the level of decimal places it equals to, you can also set round Up/Down/Nearest. In the example above i stop the bottom loop by destroying the 'User Event' this causes the bottom loop to error, stopping it. The User Event consists of a cluster of 'Daq Value' and 'Error', the error boolean is used to stop the Main loop in case of an error in the Daq loop. I also 'Unregister User Events' when exiting the main loop, im dont think this is necessary as we will be terminating, i do it anyway just in case. This is normally used to dynamically remove events.

 

Hope this helps,

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 6 of 21
(13,812 Views)

Hi fibo,

Without changing your code much, you can try this.

Let me know if it works for you.

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 7 of 21
(13,797 Views)

Fibo,

 

That code will never = True. There is also no timing structure or a stop button.

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 8 of 21
(13,786 Views)

Hey Lucither,

Thanks.yes it won't be true. I should have used not equal to function.

My intention was to tell him how he can make that case structure run only once when "x" changes.

Not to give him code which will run. So not using stop button is not going to harm him.

 

Fibo , you can use not equal to function instead of equal to.Then this will work.

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 9 of 21
(13,771 Views)

"

Fibo , you can use not equal to function instead of equal to.Then this will work."

 

I mean this idea will work for your code.Smiley Very Happy

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 10 of 21
(13,767 Views)