08-04-2014 03:29 PM
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!
Solved! Go to Solution.
08-04-2014 03:48 PM
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.
08-04-2014 03:50 PM - edited 08-04-2014 04:02 PM
@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]
08-05-2014 08:15 AM
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.
08-05-2014 08:18 AM
08-05-2014 08:21 AM
@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.
08-05-2014 08:29 AM - edited 08-05-2014 08:31 AM
@monkeys wrote:
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]
08-05-2014 09:07 AM
Thank you!
08-05-2014 09:21 AM
@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.