05-28-2013 04:03 AM - edited 05-28-2013 04:26 AM
We've all been there, don't worry. If you're interested in learning how to do it better, make sure to pay attention to everything Altenbach tells you, he's really experienced and like helping others.
05-28-2013 04:15 AM
Hello everyone,
Find the attached vi,where in I have used 3 sets of sub vis. In each vi I will be getting new value for every 250ms( here I have attached a constant value). The sub vi should give me max value and average value. These should be stored in respective places of a table. These three sub vis use different parameter and hence i have given different constants.
Problem: Since i have given constant values i should have got 23.5 as max value and 23.5 as avg in (1,1) and (1,3) respectivly. Similarly 44 in (1,4) and (1,6). But i'm getting wrong answers. what may be the cause?
05-28-2013 04:30 AM
You haven'tincluded the sub-vi but it's not needed to spot the problem.
You have three processes writing to the same table property node. Each of these overwrites the last and the order of writing is essentially random. You need to pass the wire for the table from one sub-VI to the other and have each one add only tha part they are responsible for. Then, at the end, write to the terminal of the table, not the property node.
If you create three tables and wire each sub-vi up to its own table, you'll maybe get a picture of what's going wrong. Given these three tables, an execution of your original program will gove ONE of these as a result, but not the combination of all three.
05-28-2013 04:50 AM
Hello,
I have attached the sub vi, can u please elaborate and tel me what exactly is wrong??
05-28-2013 10:58 AM - edited 05-28-2013 11:04 AM
@sushmith_ks wrote:
Find the attached vi,where in I have used 3 sets of sub vis. In each vi I will be getting new value for every 250ms( here I have attached a constant value). The sub vi should give me max value and average value. These should be stored in respective places of a table. These three sub vis use different parameter and hence i have given different constants.
Problem: Since i have given constant values i should have got 23.5 as max value and 23.5 as avg in (1,1) and (1,3) respectivly. Similarly 44 in (1,4) and (1,6). But i'm getting wrong answers. what may be the cause?
OK, as Shane already pointed out, this VI makes no sense as written.
Race conditions: Whatever subVI writes to the table last will win the race and the outcome is random. The results of the first two subVIs is irrecoverably lost. Most likely you know the final size of the table from the beginning, so initialize a 2D string array before the loop starts, and place it in a shift register then have each subVI modify the table. Use a FOR loop with three iterations, autoindexing over arrays of parameters. (Only one instance of the subVI is needed!), Then write to the table after the loop with the table coming out of the shift register. No value property nodes needed at all! (After looking at your subVI, there is a similar race condition in the subVI).
Improper loop use: since the number of iterations is knowen before the loop starts, yuo need a FOR loop, not a while loop. In fact since each iteration simply seems to overwrite the result of the earlier iteration, the outer loop does not seem to be needed at all.
05-28-2013 11:02 AM - edited 05-28-2013 11:04 AM
@sushmith_ks wrote:
I have attached the sub vi, can u please elaborate and tel me what exactly is wrong??
Everything! Way too many local variables and value property nodes. Look at "action engines" to see how to store local data between calls. Similar to the main VI, there is a race condition that you operate on the same table values in parallel and whatever writes last wins.
05-28-2013 11:12 AM
Hello Sir,
Can you please modify the code and give me?? So that I will get some idea..
05-28-2013 11:58 AM
I started changing our code today but gave up because it's unclear what you're trying to achieve.....
05-28-2013 12:01 PM
05-28-2013 12:44 PM - edited 05-28-2013 12:46 PM
@sushmith_ks wrote:
Can you please modify the code and give me?? So that I will get some idea..
Your code make absolutely no sense, so it is beyond repair. Instead, tell us where the data comes from and how the table is initially formed and what it is supposed to do. How and when do the values stored in the front panel objects get reset?
Also, since this seems to be a different problem from the "diagram editing slow" topic of this original discussion, you should probably have started a new thread for this new question.