LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Store to file and backup at same time

Solved!
Go to solution

Hello!

 

We have a very well working measurement software written in LabView. However we would like to backup the data files regularly. We want to be able to do this even during measurement and while the software is writing to the files. Now when we try to do so, we occasionally face "Error 5 occurred at Open/Create/Replace File" (in "Write To Spreadsheet File") because another software (backup, windows stuff, else...) accesses the files also. Now from my point of view this kind of concurring file access should not be a problem since LV is the only software writing to the files. There are 3 possible solutions I can think of:

  • delay the write (not feasible since you don't know how long to delay, e.g. how long the other software stays open)
  • queue the data and write it on next try (e.g. https://decibel.ni.com/content/docs/DOC-7212 - but again; how long to queue?)
  • the proper thing is; copy the file to a temporary one, edit the temporary, delete the original and move the temp. in this place

the last one should be the proper solution and also work on different OS since the copy/moving stuff should be atomic operations and thus safe in this context. However I implemented the solution and still have exactly the same problem but now in "Move File"... I am starting to doubt if it is possible to solve this issue at all and thus desparatly need help here! As I can see there is not lock or mutex on the file and no need for LV to raise an error (I think it is done as warning for future possible conflicts)... I assume it is some hidden/strange badly documented Windows API "feature" LV is using to detect those other accesses and it results in a behaviour I cannot change or fix - so what to do here...?

 

Thanks a lot in advance for any helpful suggestions or hints! Greetings

Ursin Solèr

0 Kudos
Message 1 of 7
(3,812 Views)

My sense the problem is that the backup software tries to get an exclusive lock on all the files that it is going to backup. They do this on the assumption that you don't want to save a file to which someone else is actively writing - which, by the way, usually isn't a bad assumption.

 

Are you needing to make this change without any modifications to the original LV program?

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 7
(3,792 Views)

> the backup software tries to get an exclusive lock on all the files that it is going to backup

 

I am not sure with this, since essentially EVERY other software (except notepad which just open, reads to memory and closes again) causes issues and I doubt e.g. MS Word to apply exclusive locks on opened files...?! But I don't know...

 

> Are you needing to make this change without any modifications to the original LV program?

 

Would be nice but no! I was trying to solve it from the labview program (since this is the one complaining and having issues) as mentioned, but not even the "pedestrian way" (copy to temp. and do it there in order to copy it back afterwards) which should work on EVRY OS (linux, mac, windows) does the trick...?! So what to do?

 

Greetings

Ursin

0 Kudos
Message 3 of 7
(3,769 Views)

May be I should also add; it works as expected with TDMS file format - but I would prefer to write a Spreadsheet-Text-File.

0 Kudos
Message 4 of 7
(3,750 Views)
Solution
Accepted by topic author usoler

I have to correct myself here:

 

  • TDMS does not help at all - has the exactly same issues
  • only working solution found at the moment is to (protectively) open the file a the beginning and keep this refnum open all the time until the program finishes - the reading and writing in the program can be done as before and ignore this protective refnum completely (open and close another additional refnum if needed) OR be implemented more clever and use the same refnum.

Hope this helps someone else too.

Using this method I can now use e.g. MS robocopy in order to backup or mirror all data files while the LV program writes into them. A very basic and important thing for a logger... 😉

 

Greetings

0 Kudos
Message 5 of 7
(3,703 Views)

It's all about the method you want to write. Assuming you want to always backup what you write, I'd create a wrapper for your write functions to take two inputs, and write two files all the time. In your example, I'd replace the write Spreadsheet Vi with something like this:

DualWrite.png

Which will request two paths and both files will be written the same way. You control it when you want to save data. Not some external program.

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

0 Kudos
Message 6 of 7
(3,690 Views)

I Think you must have missunderstood me; the problem is you cannot open and write to a file while another external program has it opened too with exclusive access. Consider following code:

Problem.png

 

If you open the file during the "Wait" (it is closed then because "Write to Spreadsheet" does open, write, close) e.g. with MS Word wich does an exclusive open (allowing exclusive access only) then during the next loop your program will crash with error 5.

 

The solution I mentioned is to open it first in LV an keep it open all the time:

Solution.png

which prevent e.g. MS Word to open it exclusively but read-only!

 

What you mentioned is regarding a backup - I considered this double write long before, but it is no good solution, beacuse e.g. the other drive might be a network drive and I don not want to handle absent drives - that's something the external backup tool should do.

0 Kudos
Message 7 of 7
(3,661 Views)