LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

File manipulations

I want to be able to do the following :

1. I have two text files - Current and History in a folder.
2. Current .txt  gets written with 10 values and thereupon,  History.txt is cleared and Current.txt content  transferred to History.txt.
3.  After the contents are transferred to  History.txt, the  file  Current.txt is also cleared for the next cycle.

I have been able to get the process partly OK ( VI enclosed - done in LV7.1 ). Can someone help me to get what I want as above.

Thanks for your time.

Wishing you all a Merry Christmas and Happt New Year !!

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 6
(3,206 Views)

Have you thought about doing the following after your 10 values are written:

  1. close the current file
  2. delete the old history file
  3. rename the current file to the history file (to rename use the MOVE FILE function)
  4. open a new current file
  5. repeat.
0 Kudos
Message 2 of 6
(3,199 Views)
There are many ways to do this, one possibility is shown in the attached VI. Modify as needed. (I only spent a few minutes on it, so please check for errors ;))
 
I would recommend to use plain file writes instead of the high-level "write characters to file", which opens and closes the file at each operation. It is sufficient to open the current.txt file once and keep it open during the entire run. Just keep appending at the end, then reset eof to zero to clear it.
 
 
Message 3 of 6
(3,196 Views)
Hello Altenbach,

Yes that was the very solution that I was looking for . Thanks.

In fact  it was a revelation  that setting EOF = 0 , clears the file. Don't know where to gather such information !

I have now modified ithe VI which you had sent to effect the transfer from Current to History file based on file size rather than record count. This is easy in the actual application as I have to save something like  15 values every second for  1 hour and then move it to History. And in between if the machine is stopped, then I have to save the record count  to continue next time - however if I do this based on file size then  I don't have to worry about keeping a trcak of the record count.

Just  run the enclosed VI - I notice one small issue : the History file size mostly is of the same size butr increases occassionally . Not a big problem but would like to know the reason for this ?

Thanks

raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 4 of 6
(3,189 Views)


@Raghunathan wrote:
... the History file size mostly is of the same size butr increases occassionally . Not a big problem but would like to know the reason for this ?

I am not entirly sure what you mean, but it is very well possible that the file size returns a stale value unless you "flush" the file before trying to get the size. Stale values would cause your code to miss the first few times the size is bigger than your threshold.
 
To get the file size after each read, just tap into the "offset" output as shown in the attached modification. This is a much cleaner solution.
0 Kudos
Message 5 of 6
(3,168 Views)
Hi Altenbach,

Yes. The solution is defenitley cleaner and quite elegant.

Thanks

raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 6 of 6
(3,157 Views)