05-04-2020 11:39 AM - edited 05-04-2020 12:05 PM
Hello,
I am attempting to add a column header to categorize data logged in a text file in LABVIEW 2016. Below is the block diagram I used and how the data is displayed. I am trying to get the "Data" to stay on top without repeating.
Attempts so far:
- placed the first text file containing the column header in a while loop and the same problem occurred.
- placed the data in a while loop fixed the problem temporarily but the numeric data would not log correctly.
If anyone has faced this problem before or knows how to solve it, it would be much appreciated. Thank you.
05-04-2020 12:01 PM
You should attach a VI so we can see all of your code and why it isn't working the way you want.
Obviously, writing the row of column headers belongs before the while loop, and the writing of the actual data belongs in the while loop.
When you say "placed the data in a while loop fixed the problem temporarily but the numeric data would not log correctly." Tell us how it was incorrect.
05-04-2020 12:11 PM - edited 05-04-2020 12:17 PM
Well, you are writing an array containing a single elements. What do you expect? What if you would wire the tab delimited string from below instead?
To write the header only once, do it before the loop or place the header code inside a case structure wired to the "exist?) boolean. If the file already exists, don't write the header!
(Learn about "array to spreadsheet string". It would simplify a lot of things in your code ;))
05-04-2020 12:12 PM
I attached the VI.
Here is the data in the while loop. When I log, note how the data after the date is all the same number.
*The data I am getting is coming from a probe.
05-04-2020 12:47 PM - edited 05-04-2020 12:54 PM
Once called, your spinning the loop as fast as the computer allows. Place a small wait inside it. If you are still calling this as a subVI, it will write the same values over and over until stop is pressed. This is not what you want.
You should probably keep it as a subVI as before, How often do you call it? (If you call it often, you should keep the file open and use a file ref instead of a path as inputs)
Here's functionally identical code (but conditionally writing the full headers) for your subVI. Note that assigned terminals should be on the toplevel diagram, (i.e. outside structures! Details here).
05-04-2020 12:47 PM
I expected my data set to come out like this (Figure 1) but I think I am missing something. I replied to another post in this thread, placing the header before the loop and it worked. Now the issue is the data being outputted keeps repeating instead of continuously logging the new data points (Figure 2).
Figure 1
Figure 2
05-04-2020 12:49 PM
Thank you, I'm going to try this and see how it works.
05-04-2020 01:30 PM
I tried this VI and it worked, however the headers are not being displayed. Do I need to place it's function in the true structure instead of false?
05-04-2020 02:48 PM
It only writes the header if the file doesn't exist already.
05-04-2020 07:59 PM
@HGus wrote:
I tried this VI and it worked, however the headers are not being displayed. Do I need to place it's function in the true structure instead of false?
Well, then it does not work. 😉
At the moment, it only writes the header if the file was just created (i.e. did not exist before). If you are writing to an existing file, it will not write the header. You can make it smarter where it would read the beginning of the file to check for the presence of the header, but that seems fragile too. Best would be to remove the existing file before testing. If it contains old data, back it up somewhere.