LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Front panel updating question

Hello

I have a quick beginners question about updating values within LabVIEW, and I've made a couple of demonstrations of what I'd like to do as an example.

Basically I have two values being added together from controls on the front panel, and the result is shown in an indicator.  I would like to be able to stop that updating process, by turning off a True/False boolean switch.

Neither of the two examples I've created works, but I can't quite see why.  Is it because I am not terminating the While loops properly, and if so, how should I do that?

If anyone can offer any advice that would be great.

Many thanks,

Jonathan

0 Kudos
Message 1 of 7
(3,202 Views)

#1 is worse as that is a dataflow problem.  The updating will never occur because your event structure is stuck in an infinite while loop.  It will never end to allow the 2nd loop (which is also infinite and would never end if you managed to get to it).

 

You really need to take LabVIEW tutorials to so you'll know why that code would never work.

LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

 

#2 has a problem with the way the event structure is set up, plus it is not a good idea to put an event structure in a case structure (Put the case structure in the event case!)  If it is not set to update, and you change a numeric,that is event case is set to lock the front panel until the event is handled. But the event structure won't execute because it isn't in the path of execution.  You'd have to change the Update boolean to true, but you can't do that because the front panel is locked.

Caveats and Recommendations when Using Events in LabVIEW - LabVIEW 2016 Help

Message 2 of 7
(3,166 Views)

Thank you - yes, I need to take the tutorials.  Will do.

0 Kudos
Message 3 of 7
(3,046 Views)

Hi

I've had another go at this, being less daft this time, I hope, and come up with the following which is a modification to the standard producer consumer example.

Comments would be greatly appreciated - will the queueing VIs take care of any synchronisation problems?

The aim is to have a loop that updates continuously, independently of other code running, yet which can be stopped in a controlled manner - obviously this example doesn't make a whole lot of sense, but I am really interested to know whether the principles I've applied are sound?

Thank you!

 

Event question 3.png

0 Kudos
Message 4 of 7
(3,024 Views)

That looks so much better and looks like it should work.

 

I have one comment.  I know there are examples, and that some people will use the error generated by releasing the queue to stop the consumer queue.  I've never liked that concept of intentionally generating an error for what otherwise would be a normal step in program execution (the process of stopping the program).

 

I prefer using the queue to do that where an explicit command is sent through the queue to tell the consumer loop to stop.  Then the consumer loop stops itself and it is the one to release the queue.  Besides not misusing an error for something that truly isn't an error, it allows the consumer loop a chance to finish all the commands that may have built up in the queue in the event it has fallen a bit behind.

0 Kudos
Message 5 of 7
(3,017 Views)

RavensFan wrote:

I prefer using the queue to do that where an explicit command is sent through the queue to tell the consumer loop to stop.  Then the consumer loop stops itself and it is the one to release the queue.  Besides not misusing an error for something that truly isn't an error, it allows the consumer loop a chance to finish all the commands that may have built up in the queue in the event it has fallen a bit behind.


Just to expand on this.  When you start modularizing code more into parallel loops, you realize lifetime of the queue is very important.  Since your queue should only have 1 reader, the consumer of the queue should maintain the queue's lifetime.  So your consumer should be the one to create the queue, read the queue, and close the queue.  Again, use a command through the queue to tell the consumer when to shut down.

 

An example of when this has been a big deal for me was when I am processing a lot of data, logging it, etc.  I needed every data point to be processed.  If my producer destroys the queue, then there is a really good chance that the queue is destroyed before all of the data has been processed.  This is a failure to perform the requirements.  So by putting the stop command into the queue, the producer is telling the consumer when the last sample has been sent.  So then the consumer knows it is safe to shut down and destroy the queue as part of the shutdown process.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 7
(3,003 Views)

RavensFan and crossrulz

Thank you very much for your advice, and for reviewing my VI!

Taking advice from both of you, I have updated my program to include an exit command for the consumer loops.  I realise this is now quite far from the title of this post, but it has been a useful learning experience for me and I thought I should submit where it took me.

Thank you again!

 

Event question 5.png

Message 7 of 7
(2,968 Views)