09-15-2009 06:27 PM
Hi,
I'm trying to referencing the values in a while loop from the outside of the loop. In my case, I have a start button (boolean) with "Switch until released" action inside of the while loop. Then, if I press the "start" button, I'd like to run another sub VI which is outside of the loop.
I've tried local variable and reference of the value, but it doesn't work. Can anyone help me out of this?
Fyi, I attached my prototype.
Thanks in advance.
Jay
09-15-2009 06:36 PM - edited 09-15-2009 06:37 PM
First, you have to understand the concept of dataflow. A piece of code will execute once all of the inputs to it are available. What you have is a classic race condition.
The upper part of your code is completely independent of you lower part. The lower part will run simultaneously with the upper part. Once the lower part of the code is done running, it will be done forever because there is no code such as a while loop to keep it running. As a result, the lower part of the code will probably have the value of whatever that Value 2 boolean is at the start of the program, because the code inside the loop hasn't executed quite yet. Even if you have that Start button pressed before you start the VI, it is likely the Value 2 will be read as False before the Start has a chance to pass the true value to Value 2.
What is it you are trying to do with this code? (I have no idea what your Start to Start2 is supposed to be doing. It is in your screenshot but not in your VI at all.)
09-15-2009 06:44 PM
Of coures, I understand the concept of dataflow. The simple code was just concept to demonstrate what I'm tring to do. My current VI is too complicated at this stage, so if someone want to understand its logic, it's gonna be time-consuming. There are case and sequence structures so those two things are not going to run simultaneously. I'm not an expert on this and don't have knowledge as much as you do. But what you just write here makes me feel so bad.
Thank you for your reply, though.
Jay
09-15-2009 07:06 PM
Hey Jay, dont feel bad at all. Ravens Fan has helped many of us before when we are in your situation. I am sure his direct talk is only meant to help. We may have not known the whole picture of your VI. From the picture posted, the change of the state of "start" will only be seen by the while loop which was continuesouly pulling its value. The case structure outside will not see this change as it is already completed. You may want to consider a state machine type of structure, or use function globals to pass values of controls.
09-15-2009 07:09 PM
Thank you, Brayan.
Best,
Jay