03-06-2019 04:56 PM
Well, by looking at the "code-you-failed-to-post", I can "make a guess" at your error. Assuming you are starting with an empty file (i.e. your Program is supposed to generate a new file, writing one line per loop and therefore creating an N-line .CSV file when you loop N times), I'll guess you didn't use a Shift Register to handle the Append to File input. Since you are using LabVIEW NXG, which I haven't installed (and which I'm guessing many other Forum users aren't using), I'll allow "pictures" (LabVIEW Snippets) to pass VIs back and forth. Here's how I'd do it:
Make CSV.viand here's what it might produce (as a text file):
Test.csv
Bob Schor
03-07-2019 05:01 AM
Dear Bob,
Thank you for your response and for taking the time to write this example.
You're right that I did not use a shift register in my tests. Honestly, I don't see how it çan be useful on the "append to file" input as it simply means false on the first iteration and true thereafter.
Anyhow, I tried to replicate your example on LabVIEW NXG and it still does not work: only the last line is présent in the file.
For some reason, I cannot append the .gvi file, so here is the image of my diagram
03-07-2019 07:44 AM
As I don't have NXG installed, I can't comment on your VI (or check how it is supposed to work). But here is the Help for Append to File? from Write Delimited Spreadsheet:
Write Delimited Spreadsheet Help
If you leave this unwired, it stays False, so every time through the loop, you (over-) write a new file, meaning the final result has only the entry from the final loop iteration. You want it to be false initially, as you are creating a new file, but for every other iteration, you want it to be True. The Shift Register does this for you. If NXG's analogous function works the same way (I can't tell), then it should "work the same way".
One question -- the Write Delimited Spreadsheet function I used had two inputs, a 1D input (which I used, as I was generating one line each time to be appended) and a 2D input. The "Wire" you are showing in your Post looks like a double-line, which in LabVIEW means 2D array. Aren't you building a 1D or 2D array? Can you try using a 1D array?
Bob Schor
03-07-2019 10:01 AM
Hello Didier,
Unfortunately Bob's explanation is only correct for LabVIEW "Current Gen". I tested the functionality of Write Delimited Spreadsheet in NXG and found that it differs for NXG.
The Write Delimited Spreadsheet node in NXG is a high-level file access VI that opens a text file, writes data into it, then closes it. As it writes additional header information, it does not append data to an existing file, but replaces the whole file every time. I did not find a difference in behavior using false or true for "append to file".
I'd recommend managing the file writing yourself:
As a csv file is just a plain text file, you can use the approach shown above to stream data into one.
I attached my gvi in a zip file (I could also not attach a gvi file, will flag this with NI).
03-07-2019 10:10 AM
Thanks, ikaiser, for testing that (a) the NXG Function has an "Append to File" input (as I noted, I don't have it installed, so I can't comment on it), and (b) confirming that it Fails to Function "as advertised". I'm going to report this as a Bug.
Bob Schor
03-07-2019 10:19 AM - edited 03-07-2019 10:23 AM
No worries, I already filed the bug report myself (-:
(And filed one for the forum software as well).
Note: I found some more about the NXG functionality. I used a shipped example VI. Functionality is similar to Didier's code. Wiring a 1D array, the function is labeled "Write Delimited Spreadsheet (Waveform)", and seems to ignore the wish to append data. I ran the gvi multiple times before taking the screenshot:
Wiring a 2D array however, the function is labeled "Write Delimited Spreadsheet (DBL)", and works as expected. Please note that the first lines of the file are from the previously executed 1D array test:
03-08-2019 02:08 AM
Thank you very much ikaiser,
This is exactly what I observed. The "Write delimited Spreadsheet" node works perfectly writing a 1D or 2D table when used outside the loop.
I was hoping to use it within the loop with "Append to file" checked, writing the last measured value at each itération but it does not work. On LabVIEW 2017, I was using the express v.i. for this purpose and it worked perfectly.
Hope that NI fixes the bug rapidly.
In the meantime, I can use your solution with lower level nodes without much of a complication
Many thanks to you and Bob
03-08-2019 06:05 AM
Accidentally, as I was playing again with the "Write delimited Spreadsheet" node, I notices that the code was doing its job perfectly when the data is presented as a 2D table as in the example below.
Then the "Append to file" makes the différence when checked.
I still think it is a shame that it does not work with a single value or a 1D table without warning
But at least I found my way out