LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

recording data at particular iterations and writing to text file

Hi all,

this is my first time posting on the NI boards. I'm running into a couple problems I can't seem to figure out how to fix.

I'm collecting data using a LabJack U3-HV daq. I've taken one of the out-of-the-box streaming functions that comes with the LabJack and modified it for my purposes. I am attempting to simply save the recorded data to a text file in columns, one for each of my 4 analog strain gauge inputs, and one for time. For some reason when the 'write to measurement file.vi' executes it is puts everything in rows, and the data is unintelligible.

 

The 2nd issue I am facing, which is not currently visible in my vi, is that I am running my test for 60,000 cycles, which generates a ton of data. I'm measuring creep/fatigue with my strain gages so I don't need data for every cycle, probably for the first 1000, then the 2k, 4k, 6k, 8k, 10k, 20k, etc. More of an exponential curve. I tried using some max/min functions and then matching the 'write to measurement file.vi' with a case structure that only permitted it to write for particular iterations, but can't seem to get it to work.

 

Thanks in advance for any help!

0 Kudos
Message 1 of 10
(3,599 Views)

I have never used the write to measurement file.vi, but I typically don't used caned vis. You can write your own subvi and use the write to file or write to spreadsheet functions. At least then you can troubleshoot how to write the data just the way you want.

 

You might also use a producer and consumer loop structure. That enables you to produce the data (read) at one rate and the consume (write to file) and a differenet or varying rate.

 

I made this up real quick. You would need to add the appropiate timing to the producer loop but I added the timing array to only write data to the queue at the correct number of iterations.

 

Capture.JPG

Doug Ferguson

www.southerndaqsolutions.com
0 Kudos
Message 2 of 10
(3,582 Views)

Thanks for your reply Doug. I put the data aqcuisition and data saving in two separate loops like you said. The 'write to spreadsheet.vi' puts things where I want them as well. I haven't run the vi for more than a few dozen cycles so I don't know if it only saves when I want it to yet.

 

The issue I'm looking at now is that I wanted to be able to save comments on the spreadsheet in real time, as well as have the columns of data labeled. I also need to know what iteration the vi is on. I thought bundling the time stamp with the 2D data and the iterations would do that, but I'm not seeing it on the spreadsheet. Is that possible to do with the 'write to spreadsheet.vi'?

Thanks again!

3.5LCP straingauge v3.jpg

0 Kudos
Message 3 of 10
(3,569 Views)

carfreak,

 

Are you familiar with the Report Generation Toolkit (see here)? Using the Report Gen toolkit is really the best way to program more advanced formatting and labeling in a spreadsheet. Other than that, writing to spreadsheet is really only useful for actually writing data.

 

And in terms of the timing data, one way to keep track of the time is to place a time stamp outside and before you iterate your while loop. Then, place a time stamp inside the while loop. Compare (simple subtraction) the two stamps to get a relative time value. Then add this relative time value as an element in the array you are writing to spreadsheet.

 

Note however that this will give the relative time. If all you want is to keep track of what loop iteration you are on, you can have just a simple numeric variable that increments by one everytime it passes through the while loop. Then send that value to the next iteration of the loop using a shift register.

 

Chris G

Applications Engineer
National Instruments
0 Kudos
Message 4 of 10
(3,544 Views)

Are you using the run continuously button to execute your VI? If so, this is not a good way to run your program repeatedly. Also, your loops do not run in parallel. The second loop will only run after the first one has completed. I don't think this is what you were looking for. If you look at Doug's suggestion you will see that the two loops run in parallel, not consecutively. This is a far better design in the long run.



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 5 of 10
(3,534 Views)

I'm very new at using LV, so I don't really know much about how to execute this properly.

 

Mark, I am not using the run continuously button, just the regular run command. I went ahead and placed my while loops in parallel, which makes a lot of sense now that you mention it. 

 

Chris, you were talking about adding the iteration as an element in the array. That sounds like what I want to do. How would I execute that? I'm having trouble actually making any data other than what is processed by the streaming loop be exported to my spreadsheet. And I do not have the report generation toolkit.

0 Kudos
Message 6 of 10
(3,520 Views)

I set up a cluster that included clock tick, iteration and a data array. I just did it to represent the data type but didn't show how to write to it. Look up examples of clusters i.e. bundle by name and unbundle by name. In the producer loop you could bundle the cluster with all the appropiate data and then unbundle it in the consumer loop.

 

Adding real time text comments could be more difficult depending on the timing of your file writes. If its real fast things could back up unless you dequeue the items and wait on a dialog to hold the next dequeue.

 

If you want to have column headers use the write to text file vis. Look up examples. I typically use tab delimited but you can also use comma delimited.

Doug Ferguson

www.southerndaqsolutions.com
0 Kudos
Message 7 of 10
(3,516 Views)

Hey carfreak,

 

I've attached a screenshot that shows three different ways of trying to keep track of incrementing data and/or time in a while loop. The top loop just shows a program that demonstrates how shift registers can be used to transfer data between loops. This code just writes the iteration value to the array using the Build Array function.

 

The first loop counts iterations in an extremely round-about way... the second shows that really you can just build the array directly using the iteration count (the blue "i" in the while loop is just an iteration counter).

 

The final loop shows how you can use a time stamp to actually keep track of the relative time when a loop executes.

 

Please note that these three should not actually be implemented together in one VI. I just built them in one BD for simplicity's sake for the screenshot. As described above, the producer-consumer architecture should be used when running parallel loops.

 

Does that answer your question?

 

Chris G

Applications Engineer
National Instruments
0 Kudos
Message 8 of 10
(3,499 Views)

Chris, I think the way I have it set up the data will record based on the iteration that the loop is executing. Thanks for the examples.

 

Doug, I don't think I'm going to continue to try to add real time comments. However, I was looking at your original response and after you unbundle the cluster by name in the consumer loop, it looks like you use the build array function to recombine the data into a single stream of double type data, which is what the 'write to spreadsheet.vi' needs. How do you do that? When I try connecting different data types (double and long) to the build array function it doesn't work. The 'write to text.vi' might accomodate my needs, but I can't seem to find a way to convert the cluster to string.

 

I really appreciate all the help btw.

 

Dan

0 Kudos
Message 9 of 10
(3,464 Views)

I figured I should probably attach my vi too.

0 Kudos
Message 10 of 10
(3,463 Views)