LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Which Mode to use...

Solved!
Go to solution

 

Hi all

 

I am using the "APPEND mode (a) " while opening the file but the problem which i am facing
is that right from running the program for the first time and onwards. The data in the file
is continuously Accumulating. I want to overwrite the data in the file each time i run the
program.

 

What "MODE" do i have to use?

 

Thanks
 

 

0 Kudos
Message 1 of 4
(3,261 Views)

This is the exact behaviour of the append mkode: once the file is opened, the file pointer is put at file end so that new data are added to the existing file contents, which is preserved. If you want to delete previous file content you must simply open the file for writinh. In case of fopen (standard C library) it means using mode "w". In case you are using OpenFile from the Formatting and I/O Library you must use VAL_TRUNCATE keyword.

Both options are described in the online help for the functions, here and here, that you should carefully read to fully undertand their characteristics.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 4
(3,259 Views)

 

Thanks for the reply

 

But the "fopen" function is in the while(1) loop , i am continuously acquiring the analog signals and writing their values

to the file. If i use 'w' mode then it will write the value of the Latest iteration but i want to accumulate the values as long as the program is running and when i again run the program then the file should be over written in that case.

0 Kudos
Message 3 of 4
(3,233 Views)
Solution
Accepted by topic author mhs100

It seems to me that you are missing some very basic programming policy, independent from the instrument actually used to create an application.

Continuously opening a file (and supposedly closing it) in a loop is a very inefficient method of handling file I/O operations, since the OS have to actually put data on disk and handle closing operations and directory update on each iteration.

Unless there is some *very* special necessity to have the file permanently closed and to open it only in the moment of writing, a better policy is to open the file before the loop, perform write operations within the loop and close it after exiting the it: this permits the OS to leverage the disk buffers and to reduce slow operations to the minimum possible. With this structure you can open the file in write mode, thus deleting all existing data, and accumulate only actual data in it on every program execution.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 4
(3,221 Views)