From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI is skipping a 'For' Loop

Solved!
Go to solution

Zipped Vi is attached, the top level has "7_AD-DC producer consumer" as the title.  You'll have to dig into the folder to get to it.

 

I have attached an image of the Vi, highlighted in red is the For Loop in question.

The problem I am having is that when I run the vi set to the 0.25 to 0.5 Volt range (chosen in the producer loop not shown), it works fine, but if I run the vi set to the 1 Volt range, it skips the entire highlighted For Loop and just finishes the event.

 

The program is meant to assist with calibrating a particular device.  If you follow the error path, it runs through the top section (1605 range, 1605 mode, AC-DC Range, N Factor, etc) all the way through the indicators for "1k Reference in" and "1k Reference out".  The program runs fine up through those reference measurements, but when it is in the 1 Volt range (shown in the image) it skips the entire For Loop.  I have error wires throughout and I thought that those would prevent any race conditions and that they would force the Vi to run through as intended, but apparently not.

 

It is a bit of a spaghetti Vi, I am not the best with LabView, but it seems so strange to me that it works when set to 1/2 a volt but not set to 1 volt.  I put indicators on the items that feed the For loop, # of Frequencies and Frequencies arrays look fine, and I really can't think of what is causing the Vio to skip the for loop.

Download All
0 Kudos
Message 1 of 6
(3,031 Views)
Solution
Accepted by topic author TerryBozio

The for loop is not being "Skipped" it is executing 0 times and outputting the default data for all tunnels.  

 

You have an auto-indexed input tunnel why wire the N terminal at all? The loop will perform the least number of iterations it can.  Either N times or the smallest auto-indexd array whatever is least.

 

WORSE: the auto indexed array is comming from a case structre output tunnel set to "Use default if unwired" so you have two possibilites.  Either there is some hidden code emptying the array before it is passed out of the case shown OR, the value of # of Frequencies is <1


"Should be" isn't "Is" -Jay
Message 2 of 6
(3,011 Views)

" Either N times or the smallest auto-indexd array whatever is least."

 

So even if I hardwire the N terminal, it will still only loop it as many times as the auto-indexed input terminal allows it to?  I thought the N terminal would take precidence.  I guess I am going to have to make a blank array for the other terminal instead of just letting it default to zero.

0 Kudos
Message 3 of 6
(3,002 Views)

Probe the orange array out of the Case structure - I'm going to guess it's empty. I would also highly recommend that you uncheck "Use Default if Unwired" on that array output. That way you'll see if you actually wired the array to the tunnel - you might have instead accidentally wired it to a different tunnel behind the one you wanted. If that array is empty, the for loop won't execute, because the for loop auto-indexes on that array as well as the Frequencies array.

 

Have you considered setting a breakpoint just before that loop, then running with execution highlighting to watch what happens?

 

EDIT: Jeff beat me to it.

Message 4 of 6
(2,997 Views)

@TerryBozio wrote:

" Either N times or the smallest auto-indexd array whatever is least."

 

So even if I hardwire the N terminal, it will still only loop it as many times as the auto-indexed input terminal allows it to?  I thought the N terminal would take precidence.  I guess I am going to have to make a blank array for the other terminal instead of just letting it default to zero.


Or turn of auto indexing and index inside the loop


"Should be" isn't "Is" -Jay
Message 5 of 6
(2,996 Views)

Thanks for the help guys, I think I've got a handle on this one now.

0 Kudos
Message 6 of 6
(2,977 Views)