From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Variable creation in while loop

Solved!
Go to solution

Hi,

       I am using various indicators in a while loop.Whether for each iteration new variables

(TMVol1,TMVol2..etc)will be created? VI screenshot attached for reference.

If yes,how to overcome this problem. Whether place the indicators outside while loop and using value propery node inside the loop is better  ? Please give a solution

regards

rakesh g

0 Kudos
Message 1 of 9
(3,401 Views)

Do not attach partial pictures of code -- it is so worthless that many of us won't bother trying to help you.

 

Do you understand the Principle of Data Flow?  If an indicator is inside a loop, and has a wire going into it, its value will be updated once/loop, while if it is outside the loop and connected by a wire exiting from the loop, its value will be update when the loop exits.  From your Post, it is unclear (to me) what you want to do, or whether you just don't understand this basic principle.  Note that you can "see for yourself" by creating a simple While loop containing a Stop control, a random number generator, and two indicators, one inside the loop, one outside, both wired to the Random function.  Run it -- the one inside will update so fast it will be a blur, while the one outside will remain at 0 until you hit Stop.

 

If you want some behavior different from these two extremes, describe what you want to do, try to come up with a "how to do it" using simple stand-alone code, and if you get stuck, attach your VI and ask for help.

 

Bob Schor

Message 2 of 9
(3,382 Views)

That I understood sir, I am asking for each iteration of while loop whether the a new variable is created (or new memory is allocated for the indicator or not). 

In the attached VI i have several indicators like TmVol1, TMVol2.....

I am continuosly acquiring data from a DAQ  and monitoring thr current and voltages. Some other VI is putting data in Queue and this VI displays the data in trend and indicators.

I got delay after some time . So I am trying to optimize my VI.

My main doubt is about the indicators in while loop. for each iteration of while loop whether the a new indicatoris created or not? pls tell your comments about my VI...like any nonsense...Please help.  

 

 

regards

rakesh g

 

 

 

0 Kudos
Message 3 of 9
(3,347 Views)

I think you are confused by terminology.

 

You talk about variable creation and talk about new indicators.  You can't create variables in LabVIEW if you are thinking in some text-based language manner.  You can't create indicators in a VI while the VI is running.

 

You have a lot of tunnels with the Use Default if Unwired option checked.  So if a case runs where there is no wires, those values will become 0.

 

There is a lot of crazy array, cluster, and waveform manipulation going on there.  I don't understand what you are trying to do.  That tells me you don't understand how to program whatever you are trying to do.

 

First I think you should take some online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
Learn LabVIEW

 

Then write down what you are trying to do on paper as either a flowchart or some pseudocode.  Perhaps then you can start rewriting your VI block diagram from scratch after you've organized your thoughts.

Message 4 of 9
(3,343 Views)

what is the crazy crazy array, cluster, and waveform manipulation. I dont understand?

 

I clearly stated that I am continuosly acquiring data from a NI DAQ card  and monitoring the current and voltages. Another VI is putting data in Queue and this VI deques the data update it in a trend and indicators. 

Else how can I add the data to chart?

0 Kudos
Message 5 of 9
(3,341 Views)
Solution
Accepted by rakesh@labview

This.

 

PowerMonitoring_BD

 

Everything after the For loop makes no sense.  You are taking the first two elements of an array of waveforms, which will only have two elements because the For Loop ran twice. Then bundling them into a cluster.  Then turning that cluster back into an array.  If you eliminated all 3 of those functions you'd wind up with the same result!

 

And inside the For loop, you are taking single elements and turning them into an array with a t0, so a single element waveform.  Why?

 

But you append them to an array of waveforms that comes from outside the big While Loop at the end.

 

But that incoming array you proceed to delete everything from it turning into an empty waveform array. 

 

So you have a Rube Goldberg that takes any waveform array and makes it empty.

A Loop that does, I don't know what with some scalars turning them into waveforms.

A series of functions that takes a 2 element waveform array and does cluster gymnastics to turn it back into itself, another Rube Golberg!

 

I modified the VI and attached it with other comments.

Download All
Message 6 of 9
(3,329 Views)

Thanks for your comments.

When I am using this VI it is slowing my application. Whether it is because of the errors I did in for loop ?

Or My main doubt is about the indicators in while loop. for each iteration of while loop whether new indicators (TMVol1, TMVol2......) created or not? 

0 Kudos
Message 7 of 9
(3,309 Views)

The extra steps you had in your code will not make your code faster. RavensFan and Bob Schor are pointing out that the code presented shows that you need to understand the fundamentals before you build more complicated systems. This is good feedback, but hard to listen to when you 'just want to quickly do this one simple thing'.All of us here were once in your position, we are telling you to do this because of our bitter experience. Listen to this advice, watch the tutorials.

 

To answer your second question... This is an example of something you will learn if you do watch the tutorials: If the indicator is in the while loop, its value will be updated at each iteration of the while loop. If you want to capture each value as the loop cycles, you should add each value to an array. After the loop finishes you can look in the array to see each value.

 

Write some pseudocode to describe what you want to do. Make simple versions of each step of the pseudocode. Use the highlight execution button and probes to understand what is happening inside your code. Build these up into the working whole. This is programming 101 and is useful for all languages let alone LabVIEW.

CLA - Kudos is how we show our appreciation for comments that helped us!
Message 8 of 9
(3,296 Views)
Solution
Accepted by rakesh@labview

No.  The stuff you did in the For Loop is not slowing your code down.  They are wasted operations, but still fast.  The reason for fixing it is because when you do something in an unnecessarily complicated manner, the more likely it is you are going to do it wrong.

 

As we've said, there is no such thing as "Creating Variables".  In LabVIEW, the "variable" is the wire.  The indicator is an already set aside memory space that happens at compile time when you add the indicator to the front panel.  Nothing is being being created while your VI runs.

 

If your VI is running slow, it is probably due to timing issues.  How fast is data being put in the queue?  You have two items that limit your timing in that VI.  "First, you have a 2 millisecond timeout on the queue which means if nothing is in the queue, after 2 milliseconds, the timeout fires.  But if you don't have any data in the queue, then it should seem that your VI is keeping up with whatever VI is producing the data and putting it in the queue.  The one problem with a short time out is that you wind up executing cases that output zeroes from there tunnels.  Do you want zeroes showing up in your chart?

 

The other item is that you have an event structure inside the same while loop.  It is pretty much just waiting for button presses.  When they don't occur, the 10 you have wired up to the timeout terminal means that the event structure holds for 10 milliseconds waiting for an event before it moves on.  So that is effectively limiting your loop rate to 10 msec.  That event structure should be in a loop of its own.  Actually, if your queue is continually getting data, then your loop should, and you would want it to, keep continuously running and processing that data.  You could probably get rid of the event structure and put the two event cases each into its own case structure.

 

If things are still slow, you should provide some more details on how slow it is and how fast you expect it to be.  The issues might be in other areas of your project.

 

 

Message 9 of 9
(3,277 Views)