LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write to spreadsheet

Solved!
Go to solution

I am trying to write data from a two dimensional array into a spreadsheet file (tab delimited).  When I run the vi I am first prompted for file name.  After I enter the file name the vi successfully logs one sample of data from the array and stores it in the file I specified.  Then it again prompts for a filename and stores one sample of data.  How do I modify the attached vi so that it continuously writes the data to a single file?  Idealy I would like front panel control for starting and stopping data collection.  Any help is appreciated.

Martin

0 Kudos
Message 1 of 10
(3,751 Views)
Solution
Accepted by mauimart

Wire a TRUE constant to the Append to File Input of your VI, add a shift register for the file name intialized with the empty path constant (or a path control).  Wire the shift register to the Input file path and file path out.  You can enclose the write to spreadsheet file vi in a case structure with front panel control, wire an empty path to the file path out terminal of the false case so it will prompt for a new file when you restart logging.

 

-Darin

0 Kudos
Message 2 of 10
(3,748 Views)

Darin,

Thanks for the quick response.  It works!  Any idea how to add a timestamp column to the data?

Regards.

Martin

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

A couple of comments/questions.  First, you should change to Boolean constant to TRUE, right now you are overwriting the file each time.  Second, the sub-vis which probably contain sub-vis are not included when you attach the vi, so I can't see exactly what is going on.  I assume that you want the timestamp to be the same value for all rows of the 2D data, so you need to insert a column into the 2D array.  To do that:

 

1. Find the number of rows using ArrayLength, or use a fixed number if you know it

2. Build an array using the time stamp as the element with the number of elements equal to the number of rows

3. Use the Insert Into Array vi to insert the column into the 2D data, wire 0 to the column index

0 Kudos
Message 4 of 10
(3,727 Views)

Hi Darin,

This is really helpful to me.  I have the same question about the timestamp...could you add a few more details to...

 

"Build an array using the time stamp as the element with the number of elements equal to the number of rows"

 

I have a WHILE LOOP so I assume that placing the TimeStamp function in the while loop will give me a timestamp for each iteration. 

 

I did my best to follow your instructions, and I am getting a time stamp, but,...I didn't use the INSERT INTO ARRAY function that you describe.  I tried to use the INSERT INTO ARRAY but, could not figure out how to wire it properly without error, so, I deleted it to see if I could figure out what happens without it.   Is my code putting a time stamp on the temperature measurement, or I am being fooled some how????

0 Kudos
Message 5 of 10
(3,261 Views)

Sorry, left out the attachment...

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

I'm confused as to whether you are having an issue for the timestamp or not.  Is it working or do you have a problem?

 

You are going through a lot of nonsense to convert the timestamp array to a double array, then a whole bunch of conversions back and forth through the blue dynamic datatype.

 

You should convert your timestamp to a double inside the loop.  Build array with it and the 4 datapoints inside the loop (now you have a 1-D array).  Then autoindex that wire out of the loop to give you the 2-D array to feed into the Write to Spreadsheet file function.

 

Another thing confusing me is to why you are creating 4 DAQm tasks on every iteration of the loop, acquiring 1 sample, then clearing them, and doing it in a sequence among the 4 channels.  You should create the daq mx task outside the loop before it starts, and clear it after the loop ends.  Only acquire the data inside the loop.  But when you do create the task, create it with all 4 channels at once, and do a DAQmx read of N channels 1 sample inside the loop.

 

 

0 Kudos
Message 7 of 10
(3,251 Views)

Hi,

 

Thanks for the input. 

 

The timestamp appears to be working since I am seeing timestamp data that is approximately what I would expect, so, it appears to be working.  The reason I asked you about it is because I did  not use all the functions that you suggested, so, I was wondering if there is something missing from mine that might limit this VI somehow??

 

I appreciate your thoughts on improving the VI.  I will try to implement your suggestion and see if I can get it to work. 

 

Do you expect that your suggestions would shorten the execution time?  The current execution time is about 4 seconds per loop, which is pretty slow for simple temperature measurements.

 

Thanks again,

Dave

 

 

0 Kudos
Message 8 of 10
(3,230 Views)

Yes.  It would greatly shorten the execution time.  Each creation of a task and clearing of it takes some amount of time.  Multiply that by 4 since you are doing it 4 times in a row.  So a 4 second loop time sounds very likely.

 

If you create a task before the loop, read all 4 channels at a time in the loop, and clear the task after the loop, the loop cycle time will be extremely fast and you will have to put some sort of  wait statement in there (more than the 1 msec you have now) just to slow things down to a more desirable speed.

 

If you do continuous samples, assign an acquisition rate, and do N channels, N samples, you can acquire more data at once and make the loop more efficient, and the sample timing more consistent.  At which point you'd probably want to use a Producer/consumer architecture to pass the data out of the loop with a queue to another loop that does the writing to file for you.

Message 9 of 10
(3,225 Views)

Thanks, I am going to try that and see if I can get it to work faster.

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