csvlabview

LabVIEW to .csv: Data in Header Line


I am working on an assignment to become familiar with NI LabVIEW. The assignment uses a pre-built VI and requires adjustments to accomplish a set of tasks. The pre-built VI is wired as follows:

block diagram excerpt

There is another Write to Text File function inside the loop with the %f format and , delimiter. When opening the .csv file, the first line of data is on the same row as the headings put in through the Write to Text File function in the image. Is there a way to move the data start to the next row without changing the setup blocks?

I have tried the /r and /r/n new line delimiters, but that just adds them as text without solving the problem. A double comma just gives a blank cell between the last header and the data.


Solution

  • Your Write to Text File function writes a string or an array of strings as lines to a file. If you wire an array of strings to its input it writes each string as a separate line, separated with the the appropriate end-of-line character(s), but if you give it a single string it doesn't add the end-of-line.

    I'm not sure which parts of this code you are supposed or not supposed to modify, but if we keep the same Write to Text function there are three ways you can get it to add a line ending:

    VI Snippet of the three examples

    The third one is the easiest to do!

    To use escape codes like \n in your string constant, you need to right-click on it and select '\' Codes Display instead of Normal Display. If you do this after typing a return, the new line in your string constant should change to the end-of-line characters \r\n (if you're on Windows).