LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Export sensor data to CSV (Timestamped)

Solved!
Go to solution

Hi,

 

  • I have a temperature sensor that outputs the data from 16 positions. The output from my VI is a 16x1 array (every half a second).

 

  • I need a CSV that has 17 columns (for each position) and the first being a time stamp. Then as my program runs the temperature will fill in for each position in the CSV as time goes on. I need this CSV so I can import it into MATLAB.

 

Please can someone help, I have been trying to do this for a few hours and I am not getting anywhere with it?

0 Kudos
Message 1 of 13
(6,460 Views)

Post what you have so far and we can tell you what needs fixing.  What particular problem are you having?

0 Kudos
Message 2 of 13
(6,448 Views)

Like RavensFan said, you should post your work so far to get useful suggestions, however if you haven't already found it you might find the Array to Spreadsheet String node useful. It's under the String palette if I remember correctly (but it might be in the advanced subpalette).

 

Use a comma delimiter input for CSV (the default is Tab).


GCentral
0 Kudos
Message 3 of 13
(6,411 Views)

Hi,

 

I have uploaded the VI. Attached is an image of the output that needs exporting to a CSV. I plan to have this output every half a second, so it needs timestamping. The output is the array 'All Temps' on the top right hand side.

 

The VI has a lot on it at the moment. But the lower section is the working area for CSV. Its

 

Attached is a screenshot of what my current CSV is being generated like. Its seems to be just taking all the decimal numbers and being put into one cell for every loop. I need the 16 data points plotting in each column, where each row is the incremental time it was measured for.

Download All
0 Kudos
Message 4 of 13
(6,396 Views)

I would just use TDMS file format. It is just superior over ASCII files. Moreover, you can open it as an excel file using a free plugin (TDMS channels will be columns, groups will be worksheets. Another advantage: you can store extra parameters as TDMS properties, as global, as group or as channel level.

 

http://www.ni.com/white-paper/3727/en/

0 Kudos
Message 5 of 13
(6,380 Views)
Solution
Accepted by topic author Natejk7

So, I'm attaching a snippet that I think does roughly what you want. (You can drag-drop snippets to a block diagram) I'm not sure if the new/old change to the Spreadsheet node is because you have an older version, but it should be clear from the snippet what I've done.

 

It's basically the same as what you have but with a timestamp added. You might want to subtract a zero time (taken at the start of the program, for example) to prevent having less than totally helpful timestamps, but I don't know - maybe the default is good for you. The Build Array node needs to be in 'Concatenate' mode.

 

Note that in your attached VI, the comma isn't connected to the node...

 

exampleCSV.png

 


GCentral
Message 6 of 13
(6,360 Views)

This is good thankyou, but one its only recording the most recent data (ie when I press stop).

 

How would I make it record data X amount of values for all pixels + timestamp and to add a timer so that it has intervals when it records?

 

I uploaded my newer version

0 Kudos
Message 7 of 13
(6,353 Views)

Also do I need to convert my array to a string before this occurs because the timestamp appears as a large scientific number in excel

0 Kudos
Message 8 of 13
(6,351 Views)

The problem with Excel is that it expects dates to be stored where every 1 is a day, and every fraction of 1 is the time within the day.  LabVIEW uses 1 for every second.  So you need to do some conversions to go from LabVIEW time as a double to Excel time.  Mainly divide by 86400 (number of seconds in a day) but also to subtract a number to account for the different epoch's and also what timezone you are in.  Search the forums for Excel time and you'll find some examples how to do that.

 

Another alternative is to convert you time and date to a string in LabVIEW, as well as format your values into strings, then write that as a string array using the Write Spreadsheet File function.

Message 9 of 13
(6,329 Views)

@Natejk7 wrote:

This is good thankyou, but one its only recording the most recent data (ie when I press stop).

The problem here is I think as simple as (not) wiring a true constant to the Append option. If you read the detailed help which you can either right click on a Node and select 'Help' or using the Context Help window (Ctrl-H is the default shortcut to toggle it, if it's closed) scrolling to the bottom of the context help and clicking 'Detailed Help', which opens the same window as the right click option, then you'll see the following text:

 

append to file? appends data to an existing file, if TRUE. If append to file? is FALSE (default), the VI replaces data in an existing file. If there is no existing file, the VI creates a new file.

 

Regarding formatting and the timestamp, RavensFan already has you covered, but it's worth keeping in mind that for temperature readings around 185 deg, you probably know how many decimal places you want (and I'd guess it's not that many...) so formatting as a string array is definitely doable.

 

I'm attaching a second VI with a different approach - here I've opened the file and am keeping a file reference. After the program finishes acquisition (my outer for loop) I close the reference. You don't want to do this inside the loop, especially at higher acquisition rates (it just wastes time). In this example, I've used the Write to Text File primitive to write a string (one string per timestamp) with commas that I inserted using the node I mentioned in the first post. Note that the timestamp's format string has a comma at the end of the format specifier. You can change the timestamp format specifier to whatever suits your needs. The node with 'end' wired to it is Set File Position - I'm using this to avoid overwriting previous data.

 

exampleCSV2.png

 

 

 


GCentral
0 Kudos
Message 10 of 13
(6,310 Views)