From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data Logger VI keeps writing over data

Hello,

 

Can you explain why in the attached VI (Data Logger Tester), that my txt file keeps getting written over with only the last data point taken?  I would like to have the file operate such that I can continuously log data.  

 

The first iteration creates the file (if not already existing), then the headers and then begins to log data every 5 secs.  If the file exist, then the data just keeps logging. 

 

Thanks,

hiNi.

0 Kudos
Message 1 of 3
(2,310 Views)

When you open a file with Open/Create/Repalce File, the File Position is set to the beginning of the file.  That is generally where it should be to read a file. However, when you write to that position every time the VI is called, it simpy overwrites the prior data.

 

You need to add Set File Position from the Advanced File Functions palette and set it to "end".

 

Lynn

Message 2 of 3
(2,305 Views)

What you really should do here is make an Action Engine.  You will want to save the file reference in a shift register.  That way, you only try to open the file once and it stays open.  You can do a check for a Not A Refnum to make sure your file is open.  When I do an Action Engine for a file, I usually make an explicit case for opening/creating the file, a second for writing to the file, and a third for closing the file.  I typically do not include a read just because you do not want to have to deal with  the file pointer when streaming data to disk.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 3
(2,304 Views)