LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop doesn't record all data

Solved!
Go to solution

Hello,

 

I have a LabView program containing two while loops. The first is used to increment a frequency on our machine and the second, which is inside the first, is used to take a set number of data points at that frequency. After taking those data points, the frequency is supposed to increase again. This happens for a set number of times.

 

The problem I am having is that the data file that the data points in the second while loop are supposed to be written to does not show all of the data points the program should have taken. For example, if we want the first loop to increment 10 times and the second to take 5 data points each time, we expect to see 50 data points in our file. But, we only see 10. The file always only shows an amount of data points equal to the iterations of the first while loop. So it cuts off our data at that point.

 

Does anyone have any clue what our problem could be?

0 Kudos
Message 1 of 31
(3,042 Views)

Put that error wire on Shift registers instead of tunnels! Then you will be able to troubleshoot why you are getting those Timeout Errors that cause readings to be skipped.  And move that "open file" outside all loops.   you will peeve off te OS reopening it


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 31
(3,033 Views)

Hi bcooke,

 

I cleaned up your VI and removed all unneeded things to examine your problem. Now the VI saves as much data as is requested...

 

- What's the point in using a while loop that iterates only once?

- What's the point in using WHILE loops when you know the number of iterations in advance and so should be using FOR loops?

- What's the point in opening a file in each iteration of the innermost loop, but closing it only once at VI cleanup?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 31
(3,029 Views)

I have tried pulling the open file part outside of the loop and that didn't help. Also, I'm not sure what you mean by shift registers (I'm new at this)

0 Kudos
Message 4 of 31
(3,006 Views)

In your program, I don't see how to communicate to the machines I need to talk to.

 

In response to your questions, the reason for the while loop with one iteration was to make the program wait a certain amount of time before moving on to the next step. We used while loops instead of for loops because that was what we learned how to do first. I changed when the program opens the file (moved it outside) and we are still having the same problems.

0 Kudos
Message 5 of 31
(3,002 Views)

You should go through th eLabVIEW tutorials and learn about data flow. Your delay loop (which is not necessary at all) will not work as you intend since the string control will read the value at the very beginning of the loop. It will not see any input from the user unless the type VERY fast. This is one case where you can use a flat sequence with the Wait in the first frame and the control and VISA write in the second. Even better would be to use an event structure. It is perfect when you need to wait for user input. The example that was posted was just that, an example of how to write the data correctly. It was not meant to be a working version of your code.

 

There is no need to do the file size and set of the file position. LabVIEW will keep track of that for you as you are writing the data to the file. You should probe you r error wires. I suspect that you are not waiting long enough for the instrument to reply therefore you are not reading all of the data you expect.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 31
(2,990 Views)

Mark,

 

The wait we were using was not there for it to wait for an input. We had an input that was continuously used (and we know this part is working correctly). We just needed it to wait before executing the next step.

 

And the issue isn't that we are not waiting long enough for the instrument to reply because we tested this already and we can get the data - it just isn't writing it all.

0 Kudos
Message 7 of 31
(2,977 Views)

@bcooke wrote:

Mark,

 

The wait we were using was not there for it to wait for an input. We had an input that was continuously used (and we know this part is working correctly). We just needed it to wait before executing the next step.

 

And the issue isn't that we are not waiting long enough for the instrument to reply because we tested this already and we can get the data - it just isn't writing it all.


Well f there was a file access issue the error would be missed since the write was just on top of the error wire not connected to it (One reaon for the Shift registers) There is no error handleing whatsoever without them

 

If yo need to wait between two steps yo need somedata dependancy to force execution order.

 

Comments in code let the next developer know what you tred to do  Free text and structure lables can really add clairity.

 

I Took the liberty to demonstrate.

1a.png


"Should be" isn't "Is" -Jay
Message 8 of 31
(2,966 Views)

@bcooke wrote:

Mark,

 

The wait we were using was not there for it to wait for an input. We had an input that was continuously used (and we know this part is working correctly). We just needed it to wait before executing the next step.

 

And the issue isn't that we are not waiting long enough for the instrument to reply because we tested this already and we can get the data - it just isn't writing it all.


OK, since you are confident your code is working so well and written corrrectly I will refrain from providing any more advice. After all, I have only been writing LabVIEW code for nearly 20 years, am a Certified LabVIEW Architect and a LabVIEW Champion. What the hell would I know?



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 31
(2,957 Views)

Jeff,

 

I tried following your example (though I still have while loops where you have for loops) and I'm getting the same issue.

 

I don't quite understand what you mean by shift registers. How do I fix that part?

 

Thanks.

0 Kudos
Message 10 of 31
(2,912 Views)