02-15-2023 04:52 PM
Hopefully this will be the last line of questioning I have about this program I have been working at. Firstly, I would like to thank the community for being so helpful. Now onto my inquiries. I tried using the writedelimtedspreadsheet to make it so Labview makes the file after data collection and it worked, but there are now some issues with my formatting pictured in the attached .png file. I had an old format I liked but now I have broken it and have tried to understand why to no avail. My other question is, how can I make it so every time I run my program, labview creates a csv file, saves it to a folder, checks the folder on the next run, and then create a new csv file while only changing one part of its name, like a number. Once again, I appreciate all the help I have recieved, and I hope the community can help me cross the finish line of this project very soon!
Solved! Go to Solution.
02-16-2023 01:02 AM
Hi svazquez,
@svazquez22 wrote:
My other question is, how can I make it so every time I run my program, labview creates a csv file, saves it to a folder, checks the folder on the next run, and then create a new csv file while only changing one part of its name, like a number.
Don't forget to read the help for all those functions!
02-17-2023 04:27 PM
I am not sure if I am right on this, but I feel like this method still requires me to have an already created empty .csv file for it to work. I have so far been able to create a folder and am now having issues with creating files in said folder.
I get this error:
Error 1059 occurred at Open/Create/Replace File in Write Spreadsheet String.vi->Write Delimited Spreadsheet (DBL).vi->New DAQ system.vi
Possible reason(s):
LabVIEW: (Hex 0x423) Unexpected file type.
Z:\user\desireddirectory\test
I know I have not tried using the other functions you told me about but I would like to be able to understand how to create a .csv file in my newly specified path.
02-18-2023 11:21 AM - edited 02-18-2023 11:25 AM
Hi svazquez,
@svazquez22 wrote:
I am not sure if I am right on this, but I feel like this method still requires me to have an already created empty .csv file for it to work.
Your feeling is WRONG!
You need to provide a valid path including the required filename!!!
From your VI, with some comments:
Why do you write the data twice to your file?
Why do you write the header data after writing the sample data? I think I told you to write the header first!?
It could be so simple:
02-18-2023 01:33 PM
Write Delimited SpreadSheet is an "unusual" File I/O function. Writing data to a file requires the following operations:
Write Delimited SpreadSheet only has a single function that combines aspects of all three of the previous steps. You either provide a full Pathname for the file you want to write (which is usually a "new" (meaning "unused") filename (complete with drive and folder paths) or you let the system "prompt" you for a filename. It also has a Boolean input called "append to file?" (which, by default, is False). The other "unusual" feature of Write Delimited SpreadSheet is that when it finishes writing to the file, it closes the file.
So let's say you want to write a bunch of data in "SpreadSheet" format, meaning a Text File with "columns" separated by <tab> or <,> (commas), and "rows" separated by <EOL> (end of line), and you want to do this over and over again, at intervals of 10 seconds. So in your While Loop, you generate the data, call "Write Delimited SpreadSheet" with the File Path you want to use, wait 10 seconds, and repeat. Three minutes later, you stop the loop and look at your file.
What you'll see is the last record that you wrote! What happened? Well, you left "Append to File?" unwired, so each time through the loop, you re-opened the file and wrote the most recent data.
So how is this function supposed to work? You put it in a While Loop, create a Shift Register that you wire to "append to file?" (leaving the input to the Shift Register unwired, defaulting to False), and wiring the Shift Register on the right edge of the While with a True, so the next time(s) through, you'll be appending to the file. Note that you need to do the same thing with the File Name input -- use the "New Path" output to wire to a Shift Register on the right side of the While Loop, and wire the "input" side of the Shift Register to the "file path" input.
Like this:
Note that this function opens and closes the file each time through the loop. What the "True" value wired to the Shift Register to all except the first write does is to position the newly-(re)opened file to its end before writing new data and closing the file again.
This behavior is especially useful when you are logging data for long periods of time (say, once an hour for a month) and you don't want to lose your data if the computer crashes after 20 days -- you'll at least have the already-written data saved in the file. Of course, the drawback is that the more you write, the more time you spend opening the file, finding end-of-file, and closing the file for every write. "You Pays Your Money, and You Makes Your Choice".
Bob Schor