LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop unexpectedly reinitializing and starting over

First of all, I have to start off and say that the vi you see below is full of inefficient data handling tools, and violations of Labview coding guidelines. Try to look past these. This is one piece of a very large vi that was built as a learning exercise and has not been updated yet due to lack of time and resources. Most of the issues I have with it are cosmetic and deal with reducing computing time and can be ignored because the data is effectively handled; for right now, it will have to do.

 

However, I do have a functionality error... The for loop I have isolated below is nestled within a flat sequence pane (not pictured) in an effort to control timing, however this for loop is not operating expectedly. It appears that the for loop loops to N, then restarts itself and loops to N again. The flat sequence that this for loop is housed does not repeat itself, which makes me think it's an issue with something within the for loop (indexing on an input to the loop shouldn't be the issue either...).

 

What makes this stranger is that this reinitialization of the for loop does not happen every time the program is run. I believe that the for loop stops at N the first time it is run after an adjustment to the code. For example, if I change some other part of the code, then save, close and open the vi, the for loop stops properly after N iterations. After I run the program once, it usually reverts to this unwanted reinitializing behavior.

 

Any help on getting this for loop initialized properly would help! Sorry about the state of this vi...

 

 

0 Kudos
Message 1 of 12
(4,248 Views)

You have quite a few FOR loops (most are just glorified sequence frames, though :)). Please tell us which one.

0 Kudos
Message 2 of 12
(4,241 Views)

Right!! Thank you for pointing out how vague I was being!! Long day...

 

 

The FOR loop I'm having this issue with is the main FOR loop (top-level), the one for which the N is initialized as:

 

Misbehaving FOR loop.PNG

 

 

0 Kudos
Message 3 of 12
(4,231 Views)

Well, since you say this loop is enclosed in an outer sequence and more code, the problem is probably caused outside the stuff you have attached. Can you show us the full code? Are there any other local variables or value property nodes linked to that control? I suspect a race condition.

0 Kudos
Message 4 of 12
(4,225 Views)

I just can't pinpoint where the race condition would be, here is the full code.

0 Kudos
Message 5 of 12
(4,218 Views)

VI Analyzer Results ... "The Block Diagram width (20429 pixels) and height (2936 pixels) .... "    Smiley Surprised

 

a diagram especially clear and easy to read  Smiley Wink

 

Maybe take a look at this book ?  here

0 Kudos
Message 6 of 12
(4,201 Views)

@az2mt2003 wrote:

I just can't pinpoint where the race condition would be, here is the full code.


Nothing sticks out, but of course there is a lot of noise that can drown out any reasonable code analysis. How certain are you about  the validity of your observation? Are you maybe pressing the continuous run button?

0 Kudos
Message 7 of 12
(4,186 Views)

You, yourself, say that the VI you wrote was bad code that you want to fix up.  Maybe if you fix it up and reduce its insane size, the problem will either solve itself or you will be able to pinpoint its location.

 

An earlier responder recommended Peter Blume's "The LabVIEW Style Book".  This was one of the first LabVIEW books I read, and I credit it with getting me up to speed with "how to write proper LabVIEW code".  

 

Bob Schor

Message 8 of 12
(4,176 Views)

@Bob_Schor wrote:

You, yourself, say that the VI you wrote was bad code that you want to fix up.  Maybe if you fix it up and reduce its insane size, the problem will either solve itself or you will be able to pinpoint its location.

 

An earlier responder recommended Peter Blume's "The LabVIEW Style Book".  This was one of the first LabVIEW books I read, and I credit it with getting me up to speed with "how to write proper LabVIEW code".  

 

Bob Schor


I have an old version of that - probably LV 8.x - and it's still very relevant.  Good style doesn't go ut of style, I guess...

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 12
(4,154 Views)

I have no idea why, when it comes to LabVIEW, novice developers are so resistant to coding style.

 

They make their wires all crazy-bent, going behind objects, nodes plopped down almost at random - yet their text-based code is all nice and neat.  I explain to them that "messy" LabVIEW code is like randome indents - the computer could care less about random indents, but if you did that and someone else had to decipher your code, they'd strangle you.  And I would look the other way while they did it.

 

The other thing they are loathe to do is use subVIs.  I tell them it's like putting all your text-based code in main().

 

I find these analogies very helpful to those users.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 10 of 12
(4,146 Views)