LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use shared variable to trigger an event?

I want to use a shared variable to trigger an event in one application that is controlled by a separate application. I've created the shared variable (a Boolean) but don't see any way to tie it into the event structure in my VI. Is this possible?
 
George
0 Kudos
Message 1 of 19
(8,173 Views)
One possibility: Wire the shared variable to a hidden boolean indicator linked to an event, then write to a signaling property of it whenver the shared variable changes values..
Message 2 of 19
(8,165 Views)
Hello,
 
Yes, the Value (Signaling) property will change the value of a control (or indicator) as well as generate a value change event for that control or indicator, which can be handled by an event structure.  However, you'll have to be a little careful since you probably don't want to fire the event each time you read the variable, rather only when the value of the variable changes.  For this, you could use a shift register on the loop which reads the variable, so you can compare the current read to the previous read - if they are different, then your variable changed values and you may want to take some action.  Now, you could write to the value signaling property (using a property node, just in case that part wasn't clear) for an indicator or control (which you could hide via a right click on the corresponding block diagram object) as suggested if it makes sense with your application architecture to handle subsequent actions in some event structure.  Or you could simply use the result of that comparison as the input to a case selector, and conditionally execute whatever action you want to take place in that case structure.  The idea is that in this application it sounds like you're going to be doing some polling of the variable anyway, so that part of the triggering is inherently not event driven.
 
I hope this helps!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
Message 3 of 19
(8,144 Views)
Agreed, that's why I said "...whenever the variable changes". 😉


@jls wrote:
Yes, the Value (Signaling) property will change the value of a control (or indicator) as well as generate a value change event for that control or indicator, which can be handled by an event structure. 
In addition it is worth pointing out that it triggers a value change event even in the value actually does not change. For example, If you send a FALSE to a signaling property of a boolean that is currently FALSE, the event still fires. Can be quite useful. 😄
Message 4 of 19
(8,143 Views)
In addition it is worth pointing out that it triggers a value change event even in the value actually does not change. For example, If you send a FALSE to a signaling property of a boolean that is currently FALSE, the event still fires.
 

Yeah, I found out that part the hard way. Oh well, no real harm done though.

George

0 Kudos
Message 5 of 19
(8,138 Views)

It's all part of the fun of learning LV.

Yes.... those Global & Local Variables are very tempting.... 

....  and so was some sort of apple 6000 years ago  😉

Message 6 of 19
(8,135 Views)
I just spent a painful day trying to code a shared-variable event-handler and discovered the hard way what altenbach mentioned.

A shared variable triggers a value change event even if the value actually does not change.

So what kind of event is a non-event??????


Brilliant!

Some heads should be rolling at NI.

0 Kudos
Message 7 of 19
(8,041 Views)


@Tariah wrote:
I just spent a painful day trying to code a shared-variable event-handler and discovered the hard way what altenbach mentioned.

A shared variable triggers a value change event even if the value actually does not change.


Don't put words in my mouth, I never said that! 😮 I wasn't even talking about shared variables. I was talking about writing to Signaling Value Properties of some other hidden control. (Even if the new value we write is derived from a shared variable in some way, a rather irrelevant fact in this context).

Shared variables don't trigger events!

Message 8 of 19
(8,040 Views)
Sorry about that. But this thread IS about shared variables used to trigger an event. So I assumed you were talking about them.

And they do trigger the event without actually changing value. Pretty useless.




0 Kudos
Message 9 of 19
(8,032 Views)


@Tariah wrote:
And they do trigger the event without actually changing value. Pretty useless.


Can you provide a simple example that demonstrates this? I have trouble even assigning an event to a shared variable. 😉
Message 10 of 19
(8,029 Views)