ni.com is currently experiencing issues.

Support teams are actively working on the resolution.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with wait function in a while Loop (doesn't remain constant)

Hi,

 

I'm having troubles with the wait function in a while loop.
I'm using the loop to make sampling from my instrument every 2000 ms.
The test last more than 5-6 hours and I've noticed that only in the first hour the sample rate is the one I set, than it keeps falling behind and after 3 hours the sampling rate is of 7 second.

 

Don't now if it matters but I'm exporting every sample in an excel file via Write to measurement file funcion. 

 

I was wondering what could be the cause of the problem. 

0 Kudos
Message 1 of 17
(4,541 Views)

Switch to producer/consumer archtitecture.

 

Your file writing is slowing down your sampling.

 

The next fix will be to open the file once, append as you go,and close it only when the test is over.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 17
(4,530 Views)

Giving us a look at your code would probably go a long way towards finding the answer to your problem. Other than that, one possible thing that will cause a program to get slower during execution is if you are building an array in a loop, and the array continues to grow in size as the program executes. The execution will get slower and slower as the array grows bigger ang bigger.

 

Good luck.


0 Kudos
Message 3 of 17
(4,521 Views)

But the Write to measurement file function is already inside the while loop how do you suggest to do it? 

0 Kudos
Message 4 of 17
(4,519 Views)

Hi mattecst,

 

putting the FileWrite function inside the main loop isn't a proper producer-consumer scheme!

Just create an example VI as offered in LabVIEW's "File->"New…" dialog…

 

And please clean up your VI! You don't need a constant at the FOR loop "N" input, when you autoindex an array…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 17
(4,490 Views)

I'm sorry I started using Labview one week ago.

Can you be more specific?

0 Kudos
Message 6 of 17
(4,475 Views)

We really should not ask you to "give us a look at your code", as it might encourage you to attach a picture of a part of your code.  What we really want is for you to attach your code -- put the entire VI (or, if multiple VIs are involved, compress their enclosing Folder and attach the resulting .zip file) in the attachment.

 

This lets us look at all of the code, including the parts that may be causing you the problems.

 

To understand the Producer/Consumer Design Pattern, open LabVIEW, click "New ..." (the dots are important!), choose "From Template", and choose "Frameworks, Design Patterns, Producer/Consumer Design Pattern (Data)".  Study this example and apply it to your problem.

 

Bob Schor

0 Kudos
Message 7 of 17
(4,469 Views)

Hi mattecst,

 

in LabVIEW "File" menu you select "New…". Then a dialog window opens which offers several predefined example VIs and projects.

Here you will find a "producer consumer" example VI!

 

Edit: Bob named the correct English names…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 17
(4,463 Views)

Here's the VI

0 Kudos
Message 9 of 17
(4,461 Views)

I don't see growing arrays that would cause a problem.

 

I see you have the Write to Measurement File set to .xlsx, which is a relatively newer addition to that function.  I was recently involved in a thread where the user found what I would consider a bug with it.  (Formatting, not performance.)

 

I don't know how it handles all of the file writing inside.  But since Excel is a proprietary format, I'm wondering if it is so busy rewriting the file on each use that as it grows, it takes longer and longer.

 

Try changing that over so that it writes to a text file.  That should just append to data to the end.  See if that helps.

 

How big is your .xlsx file getting when it starts to take 7 seconds per iteration?

0 Kudos
Message 10 of 17
(4,434 Views)