11-22-2017 12:45 AM
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
11-22-2017 01:34 AM - edited 11-22-2017 01:43 AM
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!
11-22-2017 11:01 AM
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 --
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
11-23-2017 09:17 AM
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.