10-09-2015 01:00 AM
So in my program the shift register sends its value to Sump, an input of the formula node.
When I press the STOP button Sump will still have the last value of the shift register so if I start the program again Area will have an initial value (not 0) since its formula is Sumc=Sump+((Xc-Xp)*(Yc-Yp))/2 and Sump starts with a previous value.
How can I reset Sump to 0 when I press the STOP button?
Solved! Go to Solution.
10-09-2015 01:20 AM - edited 10-09-2015 01:25 AM
Hi patomated,
to answer your message title: You CANNOT do anything in your program after the program has finished…
How can I reset Sump to 0 when I press the STOP button?
I don't see any "STOP" button in your image: you deleted terminal labels! Never do this!
Edit:
- NEVER DELETE TERMINAL LABELS! What kind of event do you have here? A value change of "", ""??? When the labels disturb you: HIDE THEM on the front panel!
- What's the purpose of the inner WHILE loops? They either iterate just once (then you don't need them) or they run forever (then your VI isn't usable anymore)!
To solve your question: You need to initialize the shift register! I would do this rather at program start instead when stopping (aka "finishing") the VI…
10-09-2015 01:26 AM
Sorry I fixed the stop button.
The title is a bit misleading you are right, what I meant is when I press the STOP button I want Sump to reset to 0.
In my case when I press the STOP button the shift register sends its last value to it.
How can I initialize the shift register as 0? Adding an input to it does not work.
Thank you for helping
10-09-2015 01:36 AM - edited 10-09-2015 01:36 AM
Hi patomated,
Sorry I fixed the stop button.
NO, YOU DIDN'T!
DON'T DELETE THE LABELS…
when I press the STOP button I want Sump to reset to 0.
Some pseudocode:
IF STOP THEN SYMP:=0 ELSE SYMP:= result of overkill formula node
10-09-2015 01:38 AM - edited 10-09-2015 01:41 AM
Your inner while loop have no purpose than to act as a scaffold for your shift registers, they never iterate more than once. delete them and place all needed shift registers in the outer loop, where you can initialize them at program start.
Delete the hidden indicators and local variables for xindex and yindex. all you need is an initialized shift register containing an array of two elements, one for x and one for y. Nothing on the front panel. It even seems that xindex and y index are always the same, so just keep a single "index" instead.
You have serious race conditions, because incrementing the xyindex and reading the xyindex can occur in random order, but the outcome critically depends on the order.
You have many datatype mismatches. Try to eliminate all the coercion dots.
Why do you need "select" nodes if both inputs are the same? (right side of main loop)
Never delete labels (your buttons) if you don't want to show the label on the front panel, right-click to hide the label. Always show the label on the diagram for self-documentation.
Why does the event structure have two boolean output tunnels. Branch he wire outside instead.
Instead of a 2D array to keep the xy graph data, use a complex 1D array. Simpler code!
It is not clear why you are autoindexing the array in one place and not in another. It seems you want the first and second element, so just use a single tunnel and single index array.
10-09-2015 01:53 AM
@patomated wrote:
So in my program the shift register sends its value to Sump, an input of the formula node.
When I press the STOP button Sump will still have the last value of the shift register so if I start the program again Area will have an initial value (not 0) since its formula is Sumc=Sump+((Xc-Xp)*(Yc-Yp))/2 and Sump starts with a previous value.
How can I reset Sump to 0 when I press the STOP button?
WTFWYT <Face-palm> those local variables have no flow control to tell you when they are updated in regards to when the terminals are read! Both While loops in the event case<"","":Value Change> either execute once or are infinate loops! (Trigger the event, then read the controls once, then start executing those greedy loops untill you mash the "Abort" button and the CPU has time to process that nasty command!)
OH those boolean controls are "Latchers" True when the event fires so the while loops are single-shot garunteed! (Why are there loops then.... just, run though that once again....)
I gotta give you applause for the use of the select primitaves! "If Bool is True or False output the same value" (Not that the Bool could be False when the stop condition for the outer loop is True)
Did you forget to grab a cup of coffee before coding that?
10-09-2015 02:39 AM - edited 10-09-2015 02:46 AM
Hi altenbach
Thank you so much for the detailed help. I'm still new to LabView and was not aware of many alternatives you are suggesting.
So far I have:
>fixed the shift registers and placed them on the outer loop
>restored the labels
>used 1 index for x and y
I used the select nodes because I couldn't find another node that takes a boolean and outputs a double.
Also you suggested that I remove the local variables, but then how can I increment the Index whenever I press Next Point?
Concerning the autoindexing, I am writing an additional Column whenever I press Next Point, so autoindexing reads the value from the first row always (as far as I know), in the second one I removed the autoindexing and added a ROW index of 1 so it can read the second row always and change columns with the button press.
Here's where I'm at so far.
Again, Thanks for your help. Greatly appreciated 🙂
10-09-2015 02:45 AM - edited 10-09-2015 02:45 AM
Hi patomated,
I used the select nodes because I couldn't find another node that takes a boolean and outputs a double.
Put the "-1" inside the while loop and wire it through the loop border to your "index" local variable - THINK DATAFLOW!
There is so much more to clean up and fix…
10-09-2015 02:45 AM - edited 10-09-2015 02:47 AM
Hi Jeff·Þ·Bohrer,
I've just started using LabView (3 days ago to be exact), so I'm trying my best to learn through videos, books, and the ni forum so no need for applauses.
The loops do not run continuously, they execute and exit whenever I press the button "Next Point" (I re-added the labels) since it is connected to their stop if true button. However I removed one of the while loops as altenbach suggested.
I'm still working on improving it.
Thanks for your feedback.
10-09-2015 02:49 AM
Worked like a charm, thank you GerdW 🙂