03-13-2025 01:21 PM - edited 03-13-2025 01:23 PM
Hi everyone,
I realise there are a lot of posts with similar titles already, but none of them address the problem I'm having.
The "stop" function at the bottom of any while loop fundamentally does not work for me, whether its' connected to a toggle switch or any kind of function.
This is a problem for me because It's the only way I can find to regulate how often things happen.
I've attached a simple example VI to show what I mean.
Any help would be much appreciated!
(I'm very new to labview)
Solved! Go to Solution.
03-13-2025 01:26 PM
(You didn't attach anything ;))
So, what you have to understand is "dataflow". Any given "node" (be it a subVI, loop, etc) will only "return" and move on after everything inside has finished executing. A While loop has a terminal that says "If this is False, run the loop again. If it's True, move on."
The terminal doesn't stop it now, it prevents it from running again. To stop what you're doing now depends on what it is you're doing. If you have an event structure (for example), then that structure won't move on until one (and ONLY one) of its events trigger. For a Stop function, you probably want to configure one event case to trigger on the Stop button being pressed. That will exit the Event structure. Then, if you have the Stop button connected to the Stop terminal, the While loop won't execute again, and (assuming there isn't something after the While loop) the program will stop.
By the way, most people don't have the latest version of LabVIEW, so use File- Save for Previous to version 2020 or so.
03-13-2025 01:28 PM - edited 03-13-2025 01:33 PM
Code looks fine (but see below!)
My suspicion is that you are using the "continuous run" mode, so it will restart as soon as the VI completes. Don't!
Notes:
03-14-2025 10:38 AM
Thank you!
It looks like an event structure was what I really needed. I wanted to prevent the random number generator from running continuously using the while loop's stop terminal, but I see that it isn't meant for this.
I'll save my VIs as previous versions in the future too.
03-14-2025 10:50 AM
@WillGard wrote:
Thank you!
It looks like an event structure was what I really needed. I wanted to prevent the random number generator from running continuously using the while loop's stop terminal, but I see that it isn't meant for this.
In your case, everything in the loop is running as fast as the processor allows, polling the controls and updating the indicators, (not just the random generator!) and once you press stop, the entire VI goes back to edit mode. Edit mode has no meaning to the end user of your code.
You did not list any of the code requirements (when should a random number be generated, what else should happen, what is the purpose of all this?)
I have the feeling that you should not start using an event structure until you are more familiar with the concepts of dataflow. If you only want to generate a single random number on demand, I would recommend to implement a very simple state machine that can easily be expanded once more functionality is needed. You also need to decide what the indicator should show at program start and before the first random number is generated.
@WillGard wrote:I'll save my VIs as previous versions in the future too.
Start by attaching your "event" solution so we can offer more specific guidance.
03-14-2025 10:58 AM
Thank you!
The wait function does a great job here (though it's less helpful when it only waits once at the start of the simulation). I thought the stop terminal had to recieve a constant signal so thanks for clearing that up.
03-14-2025 11:15 AM
@WillGard wrote:The wait function does a great job here (though it's less helpful when it only waits once at the start of the simulation). I thought the stop terminal had to recieve a constant signal so thanks for clearing that up.
None of what you say makes any sense!
(What is "receive"/ What is a "constant signal"? "Helpful" for what? What "simulation"?)
03-14-2025 03:01 PM - edited 03-14-2025 03:03 PM
@WillGard wrote:
I thought the stop terminal had to recieve a constant signal so thanks for clearing that up.
You clearly don't understand the idea of Data Flow. Suppose you have a While Loop and a Push Button (which you label "Stop") wired to the While Loop. You precede it and follow it with a Wait of 5000 ms (= 5 seconds), and use a Frame Sequence to do the first Wait, read the Stop button, and a second Wait.
Start this running. How do you stop it, and when does it stop? Can you explain why it behaves as it does? [Think about the three principles of Data Flow].
The Stop Pushbutton is a "Push button", which means it is True when being pushed and False when not being pushed. Is this a good "mechanical action" for a "Stop Button"? How would you want it to behave? if you don't know about "mechanical actions", look it up! Did you notice that some Boolean Controls on the Boolean palette are rectangular? They all have a different "mechanical action". Also, notice that the control that (on the Front Panel Boolean palette is called "Push Button" does not have the "Push Button" mechanical action.
This is simple enough that you should be able to recreate it (if you don't know about Snippets or can't handle LabVIEW 2021), but I'll also attach the VI.
Bob Schor