LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed structure within a flat sequence within a case structure within a while loop

Hello, i am taking lab view for the first time ever and im trying to build a flashcard VI basically. i have two questions hopefully both can be answered here as both have to do with the same VI. My main problem right now is that i have the timer structure inside my flat sequence inside my case structure inside my while loop. I am trying to have my have everything reset when i change between addition and multiplication (my 2 case structure selections), even when im in the middle of the timer counting down. as you can see in the VI it does switch to the other one when the sequence stops completely. I have looked through here on the forums and, correct me if im wrong, but i cant do what i want. The sequence has to fully go through, correct? i can have it switch between addition and multiplication at will? (no matter where the timer is). maybe there is a different timing setting i could use so i could do that? 

 

second question is: how do i get the VI to stop completely when using the while loop? when i press stop, nothing happens. should i connect something else to the stop sign or place addition while loops else where?

 

 

any help is greatly appreciated. VI attached is the VI mentioned above

0 Kudos
Message 1 of 4
(3,134 Views)

Hi lighting,

 

My main problem right now is that i have the timer structure inside my flat sequence inside my case structure inside my while loop

The main problem is: why do you even think you need to do that?

What's the point of using an event structure with just a timeout event case set to wait for 800ms?

Inside of a TWL which is set to iterate 6 times at 1000ms?

In parallel to a wait function set to wait for 5 * 1000ms?

Why don't you use a simple FOR loop with a wait functions inside???

 

i cant do what i want. The sequence has to fully go through, correct?

This is basic LabVIEW stuff: THINK DATAFLOW!

A node has to finish before dataflow can continue with next node…

Hint: When you want to implement a state machine then you should do this! (LabVIEW comes with an easy-to-use state machine example project!)

 

how do i get the VI to stop completely when using the while loop? when i press stop, nothing happens.

The loop will stop as soon as the stop button actually is read and outputs a TRUE value.

As you have wired it now it most probably will need an additional iteration before this will happen - with all those wait times in your sequences.

All you need is to OBEY THINK DATAFLOW!

 

With all those bugs/misconceptions I strongly recommend to go through those beginner tutorials offered for free by NI!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(3,115 Views)

I completely agree with GerdW's comments.  I did take a brief look at your code, and will make a number of simple points that should help you --

  • Spend enough time with enough "Introduction to LabVIEW Programming" or similar Tutorials to thoroughly grasp the concept of DataFlow Programming (or you can look up the term -- Wikipedia lists LabVIEW as one of the DataFlow languages).
  • You should almost never need to use a Sequence Frame for anything.
  • Error Terminals are found on many LabVIEW functions (including Property Nodes) -- they are there for multiple reasons, one of which is to establish a DataFlow "ordering" of execution.
  • Strive to make every Block Diagram fit on a single "reasonable-size" screen, say no more than 1280x1024 pixels.  One very good way to do this is to use sub-VIs (which should almost always use the default 4-2-2-4 connector pattern, with lower left and lower right being Error In and Error Out).
  • If you are not using LabVIEW RealTime and running on a LabVIEW RT Processor (such as a PXI or RIO), don't use the Timed Structure, but use the functions on the Timing Palette.

So I've already simplified your code to "Case Structure within a While Loop", a very common pattern found in many (most?  all?) LabVIEW programs of any utility.

 

Study first (so you "know a thing or two"), document second, and Code third.

 

Bob Schor

0 Kudos
Message 3 of 4
(3,071 Views)

Adding on, if you have enough structures that your forum title hurts to read, you have too many embedded structures.

 

When you are first learning a text-based language, you're most likely told this is bad:

 

If (something) {
    If (somethingElse) {

         If (anotherThing) {

             If (testing) {
etc

 

Generally, when you get to that point, there's a better way to do what you're trying to do.  The same is true here. 

 

If you want the VI to respond to your stop button press, you likely want to avoid the flat sequence structure.  The sequence structure won't yield control of the VI until it's finished.  If it takes five seconds, it takes five seconds.

 

From reading the other replies, you don't have a VI that's responsive to input.  It'll keep pushing through long delays before getting a chance to see the input.  The tutorials are a good start for when you're beginning.  If you have other programming experience, they can help a ton to match what you know to what you need to work with to get LabVIEW working right.

 

Others said "think data flow" and that's key.  But, it helps to know what data flow means.  A node will not operate until it gets ALL of its inputs.  It'll sit and wait.  It also won't make anything available until it has all of its outputs.  You can control the order things operate by using that.  You can also make your program frustrating by abusing data flow.

0 Kudos
Message 4 of 4
(3,047 Views)