LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to an Excel File When DAQ setup is within a While Loop

Hello, I've been having an issue with trying to save my data to an excel file. I'm pretty new to labVIEW, so I used the DAQ Assistant to set up my data aquisition (I have been told it's not ideal, but I don't have the time to learn how to change it, nor is it a problem right now). 

 

I have the DAQ Assistant and all of the data within a while loop, so that the unit continuously records data until I tell it to stop, but this becomes an issue when I want to save the data to an excel file.

 

When I run the VI, the report generator will save the file every time the while loop runs through once. So, if I'm collecting data at 100 HZ for 10 seconds, I will get 10 excel documents each with 100 rows of data, rather than one document with 1000 rows of data.

 

Is there any report generation item I can use to hold onto the data and build one large table until I am ready to dump it all into one document? I've tried tinkering with several different methods of doing this, none of which are proving useful...

0 Kudos
Message 1 of 8
(2,991 Views)

There are a number of "signatures" that show you are very new to LabVIEW.

  • Your entire program seems to consist of a single VI.
  • Almost all of the work is being conducted by Express VIs
  • There is no "design" -- everything takes place in a single loop that "runs until I say to stop", doing only one thing, repetetively.
  • You have the RGT lines running through your While loop, but nothing takes place within the While loop that involves these lines -- why not do all of the RGT/Excel work after the Loop exits?
  • I notice that each time the loop runs, it builds a new Table, but only the final Table is passed out when the loop exits.  Is this what you want?  If you want all of the Tables, do you know how to make an Indexing tunnel and thereby automagically create an output consisting of an array of Tables?  [You might have to do additional processing to turn, say, an array of 10 tables with 100 rows of data into a single table with 1000 rows, but you'll have all the data and it's a simple "array processing" task that can be accomplished with a single For loop and almost no code].

Bob Schor

 

0 Kudos
Message 2 of 8
(2,978 Views)

When you are ready for a slightly more advanced treatment, consider the following:

  • A While loop that takes data repetetively.
  • A File that is opened before entering the loop.
  • Writing the loop's data to the file with the Write taking place inside the loop.
  • When the loop exits, closing the file.

Now, there's a problem caused by Data Flow -- we're now trying to do two things inside a single loop, collect some data and save it to a file.  We can't "loop" until both are done -- what if the writing slows things down so that we "miss" some data points?

 

LabVIEW (and Data Flow) to the rescue -- you need to do the Acquiring and Saving in completely separate, largely-isolated, loops that, if they have no dependency, will run "in parallel".  While the DAQ loop is "waiting for the hardware to finish", the Write loop is telling the disk what to do (and letting it do it on its own time).  This is something called the Producer/Consumer Design Pattern, which you can learn about by doing the following:

  1. Open LabVIEW.
  2. Click File, New ... (the dots are important!).
  3. Go to From Template, Frameworks, Design Patterns, and open Producer/Consumer Design Pattern (Data).
  4. Study the code produced.  Try it out.  If you have questions, ask your teacher, fellow students, a local LabVIEW Guru, or come back to the Forum.

Bob Schor

0 Kudos
Message 3 of 8
(2,973 Views)

I've had someone more familiar with LabVIEW look it over, and he gave me many pointers on things that aren't good habits, but again, I'm new to this, BUT, these things (I dont think) are causing me any issues).

 

I don't think that only the final table is passed, because if I run the program for a little bit I usually wind up with 20+ excel files open.

 

I'm not sure I follow what you mean about an indexing tunnel, but that does sound like what I'm trying to do.

0 Kudos
Message 4 of 8
(2,973 Views)

That all sounds like what I'm trying to do, a bit overwhelming, but sounds about right. I'll give it a shot, thanks!

0 Kudos
Message 5 of 8
(2,970 Views)

Is one of your Express VIs also writing to Excel?  If so, it is the culprit!  Get rid of it -- you do not want to be opening/writing/closing Files within the loop.

 

[One reason I so dislike Express VIs is that you cannot easily tell what they are doing.  I also don't like Dynamic Wires ...]

 

Bob Schor

0 Kudos
Message 6 of 8
(2,958 Views)

I guess I misunderstood what the write to excel VI does, I thought it just converted the data so that it can save to excel rather than a basic text file...

0 Kudos
Message 7 of 8
(2,950 Views)

After spending some time with the Consumer Design Pattern (Data) template, I cannot figure it out... I don't understand what most of the things do....

 

My biggest question is why are we feeding data into a data generator?

0 Kudos
Message 8 of 8
(2,884 Views)