Unable to Read the Last Values Written in a Text File With LabVIEW

Updated Aug 30, 2023

Reported In

Software

  • LabVIEW

Issue Details

I am trying to read the last values written into a text file with LabVIEW, but I get an empty output instead, I am sure the file is not empty as I am writing to it before the read operation is done.

I am using the following test program:
testcode.PNG

Solution

After a write operation, the file mark will be placed after the data that was just written, therefore, when you read the file from the current position you might get an empty value, or an End of Line error. To get the last value written, you can use the offset input terminal in the Set File Position function to adjust the file mark.

The offset can be a negative number, using this along with the from input terminal, you can move the file mark to the last position it was before the data was written, after this you will be able to read the last values written to the file.

fix.PNG

 

Additional Information

When using the Set File Position function, you have to be careful with the position the file marker is left at after a previous file operation. When adjusting the file mark, knowing the length of data that was last written will help you knowing what offset to use.
Specifying a constant value for the offset can cause problems if the data to be read is not consistent on the number of digits, white spaces, use or lack of the decimal point. These differences are reflected in the amount of bytes you will need to use to move the file mark to different positions within the file.