From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Execute Event structure only on first value change

Solved!
Go to solution

Hi all, 

I would like an event structure to execute only on the first value change. I currently have it set to execute on the value change of a boolean. I am only interested in what happens the first time the boolean changes; however, it changes multiple times during a single execution of my vi. Is there any way to limit the event structure so that it only executes on the first value change? I have attached the relevant part of my VI. Thank you in advance for any assistance you will be able to provide. 

 

Thank you,

yp21

0 Kudos
Message 1 of 12
(6,260 Views)

I can't see your VI (I only have LabView 2011 here) but you might be able to use the "First Call?" function in the Synchronization palette, then wrap all of the code in a case structure tied to it, with the False case being empty.

 

Keep in mind that this would only work if you want to run only once each time the "run" button is pressed, so if you're calling the VI several times from another VI it might not work as you want it to.

0 Kudos
Message 2 of 12
(6,253 Views)

Your boolean is an indicator, so writing to the terminal will not fire an event anyway and the loop will never even complete the first iteration

 

What is the purpose of all this? Maybe a simple case structure would be more appropriate. What else does the VI do?

0 Kudos
Message 3 of 12
(6,246 Views)

The easiest way to accomplish this is to use a shift register to keep track of whether or not your Value Change code has executed yet. Once it has, set the shift register to FALSE so that the code in the Value Change case doesn't run again:

 

Untitled.png

 

Note that the boolean wire is passed through all other event cases...this allows other events to fire before the first Value Change.

 

There are other ways to solve this problem (like dynamically registering and unregistering for the Value Change event), but keeping a state value in a shift register is probably the simplest way to start.

Message 4 of 12
(6,245 Views)

One other way to handle this is to remove the while loop around the event structure. Then the event structure will respond only once.

0 Kudos
Message 5 of 12
(6,231 Views)

As I said, the VI you posted does not make any sense, because it is not functional. The event never fires and the loop never spins. Since the controls only get read once, there is no problem anyway.

 

If this is actually a subVI, you should adapt Darrens' code, but using an uninitialised shift register that gets set to TRUE when the event executes for the first time. Then swap the two cases.

 

What is the meaning of the 28.5714ms wait inside the FOR loop. I assume you ar aware that the decimal part has no meaning here.

 

We clearly need more information. Are there any other event cases and what do they do? Is there a timeout event? Why is "mass2" an indicator? Where do the control values come from? I still think that an event structure is the wrong structure here.

0 Kudos
Message 6 of 12
(6,173 Views)

I am using a mass flow controller. The rest of the vi focuses on the operations necessary to recieve and send information to the controller. The local variable mass2 is calling on the mass flow of the controller. I would like to generate an array with the mass flow readings as time progresses. However, I only want to generate the array after the mass flow exceeds a value that I have chosen. When that value is exceeded is not constant with respect to the vi's execution. Furthermore, I do not want an array every time the mass flow exceeds that value, only the first time. I tried doing this with a case structure, but it did not work. Darren's vi looks like it does what I want it to do, with the exception that there does not seem to be a way to make it dependent on the value change of the mass flow. Should I be using a property node or something similar to determine whether or not the mass flow is greater than the desired value? Thanks for all the replies. 

0 Kudos
Message 7 of 12
(6,155 Views)

Events on front panel controls only fire when the user changes them, or when triggered programmatically through a Value Change event, so in your case the event will never fire as Altenbach explained. You should be doing this instead with a boolean in a shift register. Initialize the shift register to false. When the mass flow value goes above your threshhold, set the shift register to true. You can do this with simple boolean logic and a greater than comparison. If you need to trigger only the first time the value goes above a threshhold, you can likewise use a second shift register to track that.

Message 8 of 12
(6,144 Views)

If you are continuously reading values, an event structure is not advised. Events are for user interaction on the front panel, not for programmatical changes. Can you attach some of your real code?

 

From your description, you are using a mass flow sensor, not a controller. A mass flow controller regulates the air flow so it is always at a fixed flow rate, independent of input pressure.

 

Attached is a simple example where an array element is added whenever the massflow crosses the threshold. You can easily modify it so an element is only added once, but then you don't even need an array because there is only one element.

0 Kudos
Message 9 of 12
(6,133 Views)

Ok I'm starting to see what I need to do. I am using a mass flow controller, because I do choose the mass flow rate. However, the PD gain results in a some fluctuations around my setpoint. I want to measure these fluctuations and ensure they are acceptable. I have attached another vi. Would this one run until my mass flow is past the desired value, and after one iteration of the true case (including the full execution of the for loop), not run anymore? The wait time for the for loop is to ensure that it matches the polling rate of my vi to the controller.

0 Kudos
Message 10 of 12
(6,121 Views)