LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use Event Structure to trigger a 1 off event

Solved!
Go to solution

I am trying to use an event structure to trigger a 1 off event.  I thought that I could check for the condition that I want to trigger the event and wire this the Val(signaling) property of a Boolean.  I then created a Value Change event on this control expecting the event to trigger when the value changed from false to true.  what I find is that writing to the Val Signaling property triggers the event every time not just when the value changes.

 

The attachment is a simple vi to try and illustrate this point using the iteration counter to try and trigger a 1 off event on the 10th iteration.  The Boolean 'Once' changes from False to True on the 10th iteration but the event is triggered for every iteration.  Need to run in debug

 

Any Help much appreciated

 

Ken

0 Kudos
Message 1 of 10
(6,280 Views)

I can't open your vi because I am on a laptop without LabVIEW right now. You might want to explore user events. You have one event that fires every time and in that event you determine if your trigger condition has been met and fire the user event. You can also programatically register for and unregister for events which could also be an option. If I could look at your vi I might have a better answer. But since you said you are writing to the value signaling property, user events are the first thing that came to mind.

=====================
LabVIEW 2012


0 Kudos
Message 2 of 10
(6,267 Views)

I hope the remarks in the screenshot are sufficient to show what i want you to think about:

 

whatsthis.png

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 10
(6,264 Views)
Wire your comparison to a case structure and write to your value signaling in there. Or better yet generate a user event.
=====================
LabVIEW 2012


0 Kudos
Message 4 of 10
(6,262 Views)

 

An example how to trigger user event.

Message 5 of 10
(6,254 Views)

One thing that I should have pointed out. I don't know what you are going to do in your "one off" event. If it is a time consuming operation you should not use an event but send a message to another loop and have that loop execute the code. Otherwise your event loop will be blocked.

 

You can send messages to other loops in a number of ways. Variables, Queues, Notifiers, Action Engines, etc..

 

Attached is your vi modified to use a notifier. I also modified your conditional logic. You said you wanted to have something happen only once but you were using a less than comparison. I changed that to an equals comparison so that when i = 9 a notification is sent to a slave loop.

 

A message box will be displayed on the tenth iteration of the master loop. Notice how your numeric indicator continues to increment even with the dialog box displayed. That would not happen if the dialog box were to be displayed in the master loop.

 

=====================
LabVIEW 2012


0 Kudos
Message 6 of 10
(6,245 Views)

 


@PaulieQ wrote:

 

An example how to trigger user event.


 

 

Kudos for the example but you forgot to unregister for and destroy the user event after the loop exits.

=====================
LabVIEW 2012


0 Kudos
Message 7 of 10
(6,243 Views)

Thank you for all your comments.  I have a lot to work with.  I still do not understand why my vi failed to work as expected.  The Boolean 'Once' starts off FALSE and stays FALSE until iteration 10 when it changes to TRUE and I want the code in the 'once' Value change frame of the event structure. Having run this code the Boolean remains TRUE so should not run again because it does not change again until the execution is stopped with the EXIT button.   My vi is a simplified version of what is required for illustration only.  I have a complicated test which changes from false to true at one point in the execution and want code to execute exclusively at this point.  The solutions suggested seem to be over complicated for what is on the face of it a simple task.

0 Kudos
Message 8 of 10
(6,206 Views)
Solution
Accepted by topic author Ken_Naylor

I have seen this confusion over the value signaling property before. You would expect that it would only fire an event if you write a different value than what the control or indicator was set to. That is not the case. It will fire every time you write to it.

 

Your simplified example was writing to the value signaling property in the while loop on every iteration. That will fire the value changed event every time you write to it. Notice the property is "value signaling" and not "value changed signaling".

 

Some of the examples were complex with notifiers and user events. But the simplest one is just to put the property node inside a case structure so that it is only written when you want the one off event to fire. It does not matter what you write to the node if you are not sending any data to the event case.

 

If there is a reason you have to write to the boolean value signaling property on every iteration of the loop you can use the value written to conditionally execute code in the event case. But notifiers, queues and user events only look complicated.

=====================
LabVIEW 2012


Message 9 of 10
(6,202 Views)

Thanks for the clarification re Value Signaling.  I will bear that in mind in future.  I ended up doing what you suggested, putting the Val(Sgnl) in a case structure fron the result of an 'AND' on the two conditions I wanted to test and if the event had previously been activated. 

Thanks for your help

 

Kudos given and accepted solution.

0 Kudos
Message 10 of 10
(6,177 Views)