LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save and write data from array to file - easy one

Solved!
Go to solution

Hi,

I got this system handed over to me. I'm new to LabView and simply need to save the data that comes from array "Average Voltage"(Inside the while loop) to do some further test of our product. 

I'll like it to do similar to this. 

 

1) Save in excel file.

2) Save only when a buttom is pressed and save the next 5 ilteration. 

3) Save and manipulate the data, so it is shown in 6 colums(1 from each LED) instead of 1 long colum.

I tried different things with T/F case structure, that solved the buttom-demand. But I'm in doubt of which I should use, Write To Measurement file or Write to Delimited Spreadsheet (Using labview 15.0) to suit my propose best possible?

It also seems to be to much to handle when i try write to txt file, because it pops up with and error that I dont know how to fix, but it is telling this: 

Error -200279 occurred

 

Possible reason(s):

The application is not able to keep up with the hardware acquisition.

Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem.

Property: RelativeTo

Corresponding Value: Current Read Position

Property: Offset

Corresponding Value: 0

 

Task Name: Analog channel

 

Thanks in advanceSetup.png

0 Kudos
Message 1 of 17
(6,894 Views)

The key here is making sure your file writes don't interfere with your data collection.

For this purpose, you should look into the Producer/Consumer Pattern. You should have a separate while loop waiting to do your file write and pass the data along a queue.

Write measurement vs. Write Delimited shouldn't matter much in this case. You said you wanted an Excel file. If that's true, then you'll need to use the Report Generation Toolkit or use ActiveX. If you just want a file that can be read in Excel, I'd recommend Write Delimited.

0 Kudos
Message 2 of 17
(6,855 Views)
Solution
Accepted by topic author 08anja

I agree with Taki, but want to make a few additional points:

  • LabVIEW is a DataFlow language.  Think about the "flow" of your data.  You talk about "saving only when a button is pressed" and saving a finite set of data.  Are you collecting before the button press and just not saving?
  • Data are being collected at some rate, and presumably you don't want to "miss" any data points.  This means that you shouldn't do anything in the Collection Loop that takes a lot of time.  If your collection rate is low, and your processing is fast, you can have everything in a single loop.  Otherwise, use Data Flow techniques (Producer/Consumer is a good one) to process the data in one loop in parallel with collecting it in an independent (and asynchronous) loop.
  • How do you want to write your data?  Do you want to write it "on the fly", as it comes in, or can you wait, collect it all, format it all, and then write it "all at once"?  
  • What do you mean by "Save in Excel File"?  Do you mean a "native" Excel file, one with an .xls or .xlsx extension?  Do you mean a Comma-Separated Variable (.csv) file that Excel can read (and, indeed, usually registers itself to read, changing the icon for .csv files to "look like" this is truly an Excel file)?  If the former, I recommend using the Report Generation Toolkit.  But for the latter, you can also use Write Delimited Spreadsheet, which may be simpler to use.

Bob Schor

Message 3 of 17
(6,838 Views)
  • LabVIEW is a DataFlow language.  Think about the "flow" of your data.  You talk about "saving only when a button is pressed" and saving a finite set of data.  Are you collecting before the button press and just not saving?
  • So I should collect the finite set of data and then save them, so i dont miss out of any data? I'll just like to save 5 set of data, so that I later can calcuate an average of these 5 set. 
  • Data are being collected at some rate, and presumably you don't want to "miss" any data points.  This means that you shouldn't do anything in the Collection Loop that takes a lot of time.  If your collection rate is low, and your processing is fast, you can have everything in a single loop.  Otherwise, use Data Flow techniques (Producer/Consumer is a good one) to process the data in one loop in parallel with collecting it in an independent (and asynchronous) loop.
    Thanks, i'll look into that pattern and try with a while loop outside my other code? 
  • How do you want to write your data?  Do you want to write it "on the fly", as it comes in, or can you wait, collect it all, format it all, and then write it "all at once"?  
  • It dosent have to write as it collect. I want to open the file afterwards, so no rush there. So proberly your last advice. But my other Q, how do i format my data so it is not just in a long collum? 
  • What do you mean by "Save in Excel File"?  Do you mean a "native" Excel file, one with an .xls or .xlsx extension?  Do you mean a Comma-Separated Variable (.csv) file that Excel can read (and, indeed, usually registers itself to read, changing the icon for .csv files to "look like" this is truly an Excel file)?  If the former, I recommend using the Report Generation Toolkit.  But for the latter, you can also use Write Delimited Spreadsheet, which may be simpler to use.
  • I'll just like to be able to open it in an excel file. No need to write an excel file. 

    And thanks for your advice and time!
0 Kudos
Message 4 of 17
(6,804 Views)

I'll look into that pattern, thanks! 

And I think i'll just need to use Delimited, thats enough for me. 

0 Kudos
Message 5 of 17
(6,806 Views)

Hi 08anja,

 

As Taki and Bob said, it's important to consider the dataflow and what you would like the program to do.

 

The two file functions you cited are both high level file I/O. This means that every time that function is called, it will open a reference to a file, write data to it, and close the reference. This takes time and isn't very efficient.  I would recommend instead using a producer-consumer architecture, as well as using low level file I/O functions. The best one for your application, in my opinion, would be the TDMS file format. LabVIEW has functions to open ar eference to a TDMS file, write or read data to/from it, and close the file reference after the process is complete. TDMS files can be quite easily read in Excel with a free add on, and they're essentially a modified binary file so they allow high speed streaming while still retaining the capability to be read in Excel and contain information about the data such as channel names.

 

The error code you cited is often caused by not reading data fast enough, so you'll likely need to read them at a faster rate, or read multiple samples from your buffer.

 

As for formatting your data so that it will appear how you like, this shoudl simply come down to array manipulation. I would try probing the wires during exectuion to see what the arrays look like at the moment so you can see how LabVIEW is manipulating them. That way you can then figure out what you need to do to acheive your desired array layout.

 

Regards,

Jake A

Applications Engineer
National Instruments UK and Ireland
0 Kudos
Message 6 of 17
(6,793 Views)

Okey, I hear what you say and tried with the TDMS file but end up doing this. It works okey except that I cannot run the program while having the txt file open. This is not essensital but could be nice 🙂 

But what I end up doing is:

SavingData.png

 

It writes my data in the txt file as shown in following document. I also shown what my wanted scenario could look like. What can I do to make it look like the example below? 

 

Scenario at the moment                 
                   
2,973682 2,973655 2,973651 2,973735 2,973671 2,973716   These are from 1. measurement
2,973819 2,973866 2,97383 2,973856 2,973832 2,973725   These are from 1. measurement
2,973819 2,973866 2,97383 2,973856 2,973832 2,973725   These are from 1. measurement
2,973746 2,973829 2,973832 2,973806 2,973856 2,973846   These are from 1. measurement
2,973746 2,973829 2,973832 2,973806 2,973856 2,973846   These are from 1. measurement
2,973632 2,973656 2,973697 2,97359 2,973703 2,97364   These are from 2. measurement
2,973685 2,973792 2,973833 2,973761 2,97354 2,973701   These are from 2. measurement
2,973685 2,973792 2,973833 2,973761 2,97354 2,973701   These are from 2. measurement
2,973767 2,973743 2,973825 2,973679 2,973746 2,973754   These are from 2. measurement
2,973767 2,973743 2,973825 2,973679 2,973746 2,973754   These are from 2. measurement
                   
                   
                   
My wanted scenario ish:                 
  LED # 1 2 3 4 5 6    
# of measurement                  
1   2,988309 2,988288 2,988217 2,988285 2,988212 2,988265    
    2,988309 2,988288 2,988217 2,988285 2,988212 2,988265    
    2,988322 2,988305 2,988281 2,988294 2,988293 2,98827    
    2,988322 2,988305 2,988281 2,988294 2,988293 2,98827    
    2,988233 2,988247 2,98831 2,988236 2,988268 2,988227    
                   
2                  
    1,233123 2,988288 2,988217 213 2,988212 2,988265    
    1,2312 2,988288 2,988217 1,23 2,988212 2,988265    
    2,988322 1,2 2,988281 2,988294 2,988293 2,98827    
    1,23 2,988305 2,988281 1,2 2,988293 2,98827    
    2,988233 2,988247 2,98831 2,988236 2,988268 2,988227    
0 Kudos
Message 7 of 17
(6,782 Views)

To do what you are looking for with your file format, you can either use the TDMS format which will allow you to implement such a structure with the channel names etc. or you can save the data into the file manually. I would highly recommend using the TDMS file format because it's by far the easiest way of doing what you want. If you do feel the need to use an ASCII file format, I would stronlgy advise against using high level file I/O functions like the Write to Delimited Spreadsheet VI because it is much slower and much more memory intesive.

 

As for opening the file while it is being edited by LabVIEW, I don't believe you will be able to do this.

 

Regards,

Jake A

Applications Engineer
National Instruments UK and Ireland
Message 8 of 17
(6,770 Views)

Okey thanks. 

I'll try include the TMDS file instead. But as i have my data in an array. Can i just wire the my data from my array into the Write to Measurement(TMDS) function? 
The TMDS is supposed to be created by the Write to Measurement function, right? Or i'm supposed to use those function under file I/0 --> TMD Streaming? 

Super, then i'll dont try to do that 😉 

0 Kudos
Message 9 of 17
(6,742 Views)

The Write to Measurement File Express VI is still a high level file I/O function, so to use TDMS streaming you'll need to use the functions under the TDM Streaming palette. You could also have a read through some of the pages here if you're unsure of how to use those functions or you want to know more about how to format your data.

 

Regards,

Jake A

Applications Engineer
National Instruments UK and Ireland
Message 10 of 17
(6,734 Views)