LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loops end earlier when there is a cluster array for multiple xyplot

Solved!
Go to solution

Hello everyone,

 

I want to control a step motor (for rotational stage), a Keithley 2450 and an SR830, changing the stage degree step by step while measuring the Vac and Idc with continuously changing Vdc. The outmost while loop partially shown in the picture below is for changing degree by the step motor. The sequence structure and two inner small while loops is for measuring Vac-Idc-Vdc.

What I want to do is to show the real-time xy plot during the measurement and show the multiple xyplots for different degrees (one single xy line for one degree). So I add the disabled part and the problem comes.

When I disable the part, everything works fine. All Vac and Idc values are measured with apppointed Vdc range (such as -10 V ~10V). But when I enable the part, the two loops end half way.

I wire the errorout of write to measruement file to the shift register for errorin of the out most while loop, which doesn't work.

I am totoally confused. Can anyone help me out?

Thank you.

 

Zhu

Measure Vac-Vdc(sweep)-deg(fix)-part2.pngMeasure Vac-Vdc(sweep)-deg(fix).png

0 Kudos
Message 1 of 11
(3,969 Views)

Another thing. Recently a crash report poped up. At the bottom of the lvlog.txt, there is a sentence -

"Possible Path leak, unable to purge elements of base #0"

0 Kudos
Message 2 of 11
(3,923 Views)
  • We don't work well with pictures. Can you attach the actual VI?
  • What is your definition of "end halfway"?
  • What is in the error wires going to the termination condition of the upper loop (you don't have an indicator, so how would you know?)
  • SInce both loops typically run a defined number of iterations, why aren't they FOR loops? You can add a conditional terminal to stop early on some conditions.
  • What is the reason for building the two orange arrrays in the upper loop? Are you really appending clusters with ever increasing arrays to the lower array? Seems like a lot of data redundancy.
0 Kudos
Message 3 of 11
(3,887 Views)
Solution
Accepted by topic author zhaosir

I'm seeing one major issue.  It is a classic example of not all of the data being processed in the consumer loop due to following NI's example.

 

So you have one loop adding data into a queue.  You have a second loop removing the data.  The producer loop completes and destroys the queue.  This causes the consumer loop to throw an error due to the queue being destroyed and stopping.  But what happens to all of the data still in the queue when it is destroyed?  Answer: it is GONE.  It will not be processed.

 

Since you want every peice of data processed, you need to send a command of some sort to the consumer loop to let it know it has processed everything and then allow it to stop.  Only after the consumer loop has stopped should the queue be destroyed.

 

So what command should you use?  In this situation, I would send an empty array when the producer loop has stopped.  The consumer just checks the read data to see if it is an empty array.  If it is, it stops the loop and destroys the queue.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 11
(3,882 Views)

Hi altenbach,

 

The subVI in the disabled part is used for multiple xy plot. And there is a write to measrement file function. So I can see that for a case where I want to plot and write 100 data sets, the program only plots and writes about 70 data sets and then starts next loop.

According to crossrulz answer, I find that the reason is that the release queue is connected to the enqueue loop and the dequeue loop takes so long time that  it cannot process all data before the queue is destroyed. So I connect the release queue to the dequeue loop and it works.

I just tried the for loop, which took much more time for one iteration than while loop. I don't know why.

The two orange arrays and the cluster array are used for plot real-time xy multiple plots, showing all xy plots for all finished iterations (the outmost loop) and the ongoing loop.

 

Now a new problem comes.

The multiple xyplot takes too much time. How can I get a much more fast real-time multiple xyplot?

 

Thank you.

0 Kudos
Message 5 of 11
(3,856 Views)

My mistake. Almost no difference between for loop and while loop.

0 Kudos
Message 6 of 11
(3,846 Views)

Hello crossrulz,

 

I have reconnected the reease queue to the dequeue loop and it works.

The multiple xyplot part in the dequeue loop really takes a long time. Is there some better way to real-time multiple xyplot (real-time plot the ongoing outmost iteration while showing the plots of previous out most iterations) ?

 

Thank you!

 

0 Kudos
Message 7 of 11
(3,843 Views)

It is difficult to say where your problem originates, but there are plenty of very problematic code constructs. You have not told me why you are accumulating all that duplicate data. Autoidenxing on a while loop is dangerous. How big is that autoidenxing array? Why are you dividing by a fixed size array of 1000 elements? Wouldn't it be more reasonable just to divide by a scalar? What are typical values for start, stop, step? Why are you replacing all elements of a six element array with six new elements? Couldn't you eliminate all that and just wire the array directly to the enqueue function? Why are you reading 600000 (!) bytes just to get a single value? What are the actual inner loop rates? 

 

How are you running this? Is this a one-shot deal?

 

Also the outer while loop should be a FOR loop because the number of iterations is known from the beginning.


@zhaosir wrote:

The multiple xyplot takes too much time. How can I get a much more fast real-time multiple xyplot?

 


Probably because you are accumulating all that duplicate data. How do you determine the plot update rate? How often are new values written to them?

 


@zhaosir wrote:

 

 

I just tried the for loop, which took much more time for one iteration than while loop. I don't know why.

 


You prbably made a mistake. Show us what you did.

 

 

 

 

Message 8 of 11
(3,833 Views)

Hello altenbach,

 

 The autoindexing array is the array for setting Vdc values, one value for one iteration of inner loops. The largest range is from -20 V to 20 V with a step of 0.1 V. So the autoindexin array contains up to 401 elements. I take it out of the producer loop to reduce running time of the loop. Why is it dangerous?

I have changed dividing array to a scalar.

The typical values for star, stop and step are 0~+/-20 V, 0~+/-20 V, 0.1~1 V.

I have changed the array wiring directly to the enqueue and reduce the reading bytes to 32.

 

The producer loop runs 30 ms per iteration, about 12 s per 401 iterations (Vdc = -20 ~ 20 V, 0.1V/step), which is learnt from the time elements (the first one in the six elemen array written to the enqueue) in the write files.

The consumer loop takes much long time. For the first iteration of outer loop, the whole consumer loop takes 34 s per 401 iterations. For later iterations of outer loop, theconsumer loop takes 16 s per 401 iterations. The time is recorded manually with a timer...

 

I want to separate the instrument intialization and setting from the measurement but I don't know the proper way to do it. So I just put them into to case structures and wire two boolean controlswhich latch when released. When I want to intialize the instruments, I set values and press the initialize bool control, and then I run the VI. When I want to measure, I press the measure boolean control and then run the VI.

 

How can I improve the code for multiple xyplot? If there is no way, I think I d better change it with a single xyplot.

 

Best

0 Kudos
Message 9 of 11
(3,811 Views)

You still hanven't explained why you need to read 600000 characters to parse a single number.

There is nothing in the consumer loop that should take much time. What do you mean by "multiple xp plot"? (a graph with multiple plots, multiple graphs?) Note that you are building evergrowing orange arrays, and every time you append all existing elements as a new element of a cluster array. Instead of ending up with a graph containing N points, you will have a graph containing N plots, each with one more points that the previous, for about N²/2 points (~80k points instead of ~400 points, most of them duplicates. Seems redundant, right?).

 

Can you show us your latest code?

0 Kudos
Message 10 of 11
(3,797 Views)