LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save Continuous Data (while loop) as CSV

Solved!
Go to solution

I am controlling a power supply and I want the program to run while I change values for voltage (hence the while loop). When I stop the program, I want all data to be saved by the program prompting the user with a dialog box (for the user to enter where he/she wants the data to be stored and what to name it). It seems quite simple and I am very close with my code. My current code prompts the user each iteration of the loop with a dialog box, however I just want one dialog box prompt at the end of the program storing all the data.

 

I tried putting the "Write Spreadsheet to File" subvi outside the while loop but it only stores the last iteration of the while loop.

 

I looked in the forums to find a solution, but I could not. It seems like many people have struggles saving data as a CSV from Labview.

 

Help would be appreciated! Thank you!

 

 

0 Kudos
Message 1 of 9
(5,143 Views)

You need to break this down into steps.

 

Initlize your instruments

Open the data file file

Write column headers to the file

Change an operating peramater 

Take a measurment 

Write data to the file

Loop until done

Close the data file

Safely shutdown instruments

 

I have attached a state machine example that shows one way to do what you want. This goes a little further as it also shows how to automatically create a data file every day for an extended test.

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 9
(5,134 Views)

@monkeys wrote:

I am controlling a power supply and I want the program to run while I change values for voltage (hence the while loop). When I stop the program, I want all data to be saved by the program prompting the user with a dialog box (for the user to enter where he/she wants the data to be stored and what to name it). It seems quite simple and I am very close with my code. My current code prompts the user each iteration of the loop with a dialog box, however I just want one dialog box prompt at the end of the program storing all the data.

 

I tried putting the "Write Spreadsheet to File" subvi outside the while loop but it only stores the last iteration of the while loop.

 

I looked in the forums to find a solution, but I could not. It seems like many people have struggles saving data as a CSV from Labview.

 

Help would be appreciated! Thank you!

 

 


 

[edit] I guess @RTSLVU actually showed you the correct implentation of what you really need to do [/edit]

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 9
(5,132 Views)

That example has a lot going on. I feel like what I am asking is simple and I am almost there. I changed the code around a little bit and now it saves as DATAFILE automatically to the desktop, but I just want to choose where it goes rather than automatically declaring a path.

0 Kudos
Message 4 of 9
(5,087 Views)

Save As CSV.PNG

0 Kudos
Message 5 of 9
(5,082 Views)
Solution
Accepted by topic author monkeys

@monkeys wrote:

That example has a lot going on. I feel like what I am asking is simple and I am almost there. I changed the code around a little bit and now it saves as DATAFILE automatically to the desktop, but I just want to choose where it goes rather than automatically declaring a path.


Leave the File path input of the Write to Spreadsheet.vi unconnected.

You'll be prompted for a path.

0 Kudos
Message 6 of 9
(5,079 Views)
Solution
Accepted by topic author monkeys

@monkeys wrote:

Save As CSV.PNG


Okay, the reason for the state machine is... do you REALLY want to reinit your equipment every time?  Of course not.  Move that stuff into a separate state so you do it only once.  Same with the close - put that in a separate state also.  You only need to do that once, too.  This will probably speed up your code substantially as well as keep your equipment from potentially tripping over its tongue.  A third state is where you take your readings and stick them in a file.  THAT is why you want the complexity of the state machine.  In the long run, it's actually less complicated and more maintainable.  New test?  New state.


Good to use best practices now, while the code is still easy to maintain.

 

[edit] You never know when an engineering tool becomes released software.  Believe me, I know.  😉 [/edit]

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 9
(5,076 Views)

Thank you!

0 Kudos
Message 8 of 9
(5,068 Views)

@monkeys wrote:

That example has a lot going on. I feel like what I am asking is simple and I am almost there. I changed the code around a little bit and now it saves as DATAFILE automatically to the desktop, but I just want to choose where it goes rather than automatically declaring a path.


Yes it does, that example was for someone else who wanted to automatically create a new data file every night for a long term test.

 

But the simple state machine concept is what I wanted you to understand.

 

The sooner you get out of the habit of making programs that are "one big loop" the better.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 9
(5,064 Views)