01-20-2011 11:47 PM
Hello,
I am working on a program in which i have to control the data flow on wires.
The task is that the data should not pass on until a given value is generated. And the program remains reading the wire until that value is generated.
When that value has obtained, now the data pass on to the while loop regardless of the data that is generated latter on.
For this reason i have created two while loops one searches for that value and the other is the main which have to perform processing when the specified value is generated (taken in the first loop).
This could also be said that "Wait until a certain value is received"
The first loop is created just to wait until a value 3 is obtained.
The second loop is the main which has to process it.
Solved! Go to Solution.
01-20-2011 11:53 PM - edited 01-20-2011 11:54 PM
Hi,
Why don't you use single while loop and a Case structure? Have a look.
You can execute code written in second while loop in "True" Case.
01-20-2011 11:57 PM
Thanks gak
The thing is that, i have to search it only for the first time. And when that value is occurred now i have to do processing regardless 3 occurs again or not.
01-20-2011 11:58 PM
You can also say it like.
Wait until 3 is occurred and then go to the processing.
01-21-2011 12:06 AM
State machine architecture is best option for this.Have a look at attached vi.
01-21-2011 12:52 AM
I think that i am unable to clerify my task
This is to
"Not start the program until 3 comes"
Once 3 is occurred than run the main program
Not concerned with the value obtained
01-21-2011 01:11 AM
Hi Intelligent,
You can place your main code in "Main" state of the vi I have posted.
What You have done is, you are checking value of "numeric". If it is =3, you stop that loop and start new while loop in which you carry out further process.
I have done same thing with state diagram structure. First state is "Init". Whatever is your initial condition, is checked in this state. It will act as your first while loop. It will exit this state when your condition is satisfied.
Then it will enter in Next state i.e.. "Main". Here you can carry out further process on data as you have done in second while loop.
I think I have made myself clear.
01-21-2011 04:11 AM
Whilst your screenshot is not best coding practice, I struggled to see what you were asking for help with.
I figured out eventually what your problem was. The two while loop system you have written will do the bare minimum of what you want (although as I said, it is far from best practice and left as it is it would still have issues when running). However what you have would never progress beyond the first loop unless the Numeric was set to 3 at the start. Whether you understand the state machine or not, what you do need to understand is that terminals on the block diagram are read where they are put.
So in your diagram, the only value that will ever be compared to the three is the initial value of the numeric. Move the numeric into the while loop and it will be read in each iteration.
However, your second while loop has it waiting for a 7 before finishing, and so you would need a read of the value in that location as well. There are various ways to do this, but the best answer would be a state machine. Read the numeric OUTSIDE of the case structure, but inside the while loop. Create an enum to manage the cases. Control the cases using a shift register on the loop, initialise this (outside the loop) to "Case 1" (entry 0 in your enum). In "Case 1" look for a 3, if you have one update the shift regitser to be "Case 2", otherwise pass through the "Case 1" value. In "Case 2" look for a 7, if you find one send a True to the while condition, otherwise send a False. The System Status just needs to be wired to the not of the outcome of Numeric = 7. (The value being used as the other input for the AND will always be TRUE.)
It would be a good idea next time to actually ask a question in the first post, what you gave us was a number of statements, and a screenshot of some code which almost fills the requirements
01-21-2011 11:02 AM - edited 01-21-2011 11:06 AM
@Intelligent wrote:The first loop is created just to wait until a value 3 is obtained.
The second loop is the main which has to process it.
You have some severe misconceptions about dataflow and your code is highly flawed. Since your control is outside the first loop, any data change of the control will not propagate into the loop once the VI has started. This means that the first loop will either (1) complete immediately or (2) continue to spin forever while consuming all CPU.
Same with the second loop.
It is also very bad practive to do equal comparison with floating point numbers.
Here's a quick solution (LV 8), see if it suits your requirements. Modify as needed, e.g. add your LED back. 😉

01-21-2011 02:18 PM
@altenbach wrote:
It is also very bad practive to do equal comparison with floating point numbers.
Why is that?