03-28-2018 01:24 PM
Dear friends,
Is there a way I can let labview to write header to scv automatically? Instead of I write myself.
e.g. I have 3 input, their all already have the name (maybe from indicator or vi output name). lets say the name is a,b,c. Is there a way, it can give to the scv by itself?
in my example, there are 3 random gen, but I have to name the header myself. Thank you.
03-28-2018 01:36 PM
Nope, you have to write the header one way or another. Are you logging the data during the acquisition or after? Depending on this answer, I can get a suggestion.
03-28-2018 02:59 PM
Hi
Attached VI should get you going. Make sure you input a file path, header string array and data array(1D double). If you use this vi in the loop, it will keep adding new data without deleting previous data points. If FilePathIn is empty path, it will prompt you to create a file path so if you name your file as "YourFileName.csv", it will be created automatically. If you want to write data multiple times in a loop, make sure to feed the file path which is created in the first call.
03-28-2018 05:17 PM
Hi Ozgur,
Thanks for the VI, but it seems that I still need to write the string of header myself right? I need to give that string to the header input.. Or there is no way to do that all automatically ?
e.g like you create any indicator, the indicator always has a name automatically. like, you use the plus vi, the output indicator name is x+y .
03-29-2018 05:19 AM
@sunson29 wrote:
e.g like you create any indicator, the indicator always has a name automatically. like, you use the plus vi, the output indicator name is x+y .
Nope. LabVIEW can't do everything for you. At some point, you will have to program.
03-29-2018 08:09 AM
Hi
You can create references for each control so that you can use property nodes to pull their label, caption etc. and feed that labels into the VI I attached earlier as Headers. For ex, if you have three controls and lets say their names are x+y, x-y and x/y, you can right click on each control>Create>Reference, and connect this reference to the property node (open your block diagram, right click on the white space and you wil see property node under "Application Control" . From this property node, you can automatically get each button's label and build a 1D string array and input this array to my VI as Headers. Therefore, you can read each control's label automatically and no need to enter any headers manually.
03-30-2018 10:23 AM
thank you~
03-30-2018 12:14 PM - edited 03-30-2018 12:17 PM
Freelion8's idea will work for small programs where you are saving a few controls and indicators, but that method will not scale well. What if you are collecting large amounts of data?
You simply make a sub-vi to write you headers to the file at the same time you open the file like my example below.
04-01-2018 02:08 PM
yeah, that's what I do right now. There is a long string array~~
04-02-2018 09:19 AM - edited 04-02-2018 09:19 AM
@sunson29 wrote:
yeah, that's what I do right now. There is a long string array~~
Well there really is no other good way to do it, the headers have to be written to the file before you write any data. Also I rarely display all the data I am collecting so there's another reason Freelion8's idea is not going to work in the long run.
Only thing I have found over time typing a long string is faster than moving from cell to cell in an array constant. So I use a long string constant (or two or three...) with the headers separated by commas, then use "Search and Replace" to replace the commas with tabs before writing the headers to the file.
Making it a sub-vi then makes my block diagram cleaner.