LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use shared variable to trigger an event?

NI provides an example in the DCS module....DSC Event Structure Demo.lvproj.

I initially based some code on this example only to discover that a shared variable constantly triggers the event handler...even if the value doesn't change.
0 Kudos
Message 11 of 19
(4,173 Views)
Sorry, I am not familiar with that module. Robot wink
Message 12 of 19
(4,178 Views)
The DSC Event Structure support fires an event when ANY value related to the Shared Variable changes.  For instance, the timestamp is udpated every time a value is written to a Shared Variable, even if the same value was written twice.  The same applies to double-typed Shared Variables with a deadband.  Lets say you have a Shared Variable with a deadband of 5% initialized with the value 1.  If you write a 2, the value of the Shared Variable will not change, but the time stamp will be updated because the timestamp indicates the last time the Shared Variable was updated.  Events are also fired if the quality of a Shared Variable changes.

Depending on your application you may want to determine what part or parts of the Shared Variable were updated.  This may not matter in other applications.

-Nick F
~~
0 Kudos
Message 13 of 19
(4,153 Views)

Another option....

 

1. Create a user event

2. Fire the user event when the data is written to the shared variable (Source.vi)

3. Register for that user event in 1 or more VI's (User 1.vi & User 2.vi)

4. Now, every time the event fires in Source.vi both User 1 & 2.vi know there is new data. No polling of a shared variable is required.

 

You DO NOT need the DSC module to do this.

 

Example files are attached.

Message 14 of 19
(3,248 Views)

This works even better if you put the firing of the user event inside an event structure, whose case is the slider (data) changing value.

 

Then there is no activity when no data changes.

0 Kudos
Message 15 of 19
(2,545 Views)

I've been studying this example for an hour, and can't seem to understand how it could work the way it is explained.  From what I can see, the event is triggered every time the while loop cycles because the event data never changes (or it never triggers the event because the value isn't changing).  Either way, writing to the shared variable will not affect this.  Is there some sort of hidden functionality that ties the shared variable to the event?

 

GSinMN     

0 Kudos
Message 16 of 19
(2,350 Views)

Just what I needed.

 

Getting immersed in DSC/OPC and shared variables.  Who'd have thunk Value (Signaling)?

 

Thanks,

Mark

0 Kudos
Message 17 of 19
(2,313 Views)

Hi,

I had a visit to the block diagram. The thing is, the shared variable is being fed each 100 ms and at the same time an event is generated in order for the other VIs to recieve it.(It is done 10 times! per second). So, what's the use of it? The whole problem is about the fact that we don't know the time of updating value in the shared variable and there is no intention for polling its value to see if it changes.

0 Kudos
Message 18 of 19
(1,557 Views)

@MahyarHooshiar wrote:

I had a visit to the block diagram. The thing is, the shared variable is being fed each 100 ms and at the same time an event is generated in order for the other VIs to recieve it.(It is done 10 times! per second). So, what's the use of it? The whole problem is about the fact that we don't know the time of updating value in the shared variable and there is no intention for polling its value to see if it changes.


You are commenting on a post that is seven years old in a thread that has not seen activity in years, but yes, that code is not such a good idea in general, even if the timing is slower.

 

There is a clear race condition (this is the magic word!) in that we don't know in what order things occur. There is absolutely no guarantee that the shared variable has been updated when the event fires.

0 Kudos
Message 19 of 19
(1,543 Views)