LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Transaction Safe File I/O

Solved!
Go to solution

After some test I realized the default File I/O is not blocking files.

Is there an easy way to achieve blocking of files while I work on them?

 

I want to read some Values, process them, and then write modified Values Back. Without allowing other instances of the Same Application to interfere. Or even better with nothing allowed interfering.

 

 

0 Kudos
Message 1 of 6
(1,170 Views)
Solution
Accepted by topic author PaulPascher

Is this function suitable for you?

Deny Access Function

Owning Palette: Advanced File VIs and Functions

Requires: Base Development System (Windows)

Reopens the instance of the file specified by refnum to temporarily change what read or write access is denied to other refnums, VIs, or applications.

 
deny mode specifies what read or write access is denied.

0 deny read/write—Deny both read and write access to the file (default).
1 deny write-only—Permit read access but deny write access to the file.
2 deny none—Permit both read and write access to the file.

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 2 of 6
(1,166 Views)

@PaulPascher wrote:

After some test I realized the default File I/O is not blocking files.

Is there an easy way to achieve blocking of files while I work on them?

 

I want to read some Values, process them, and then write modified Values Back. Without allowing other instances of the Same Application to interfere. Or even better with nothing allowed interfering.

 

 


You are doing it wrong...

 

If you are using the "Read or Write Delimited Spreadsheet" or any of the "Express" vi's they do NOT lock the files.

 

They actually open the file for read or write, perform the action, then close the file every time the vi runs. (Not very efficient and as you can see does not lock the file)

 

If you use the file read/write Text or Binary file functions that need the separate Open/Create/Replace File function. LabVIEW will automatically lock the file once you open it.

 

Don't forget to close all your file references. 😛

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 6
(1,106 Views)

@RTSLVU wrote:

If you use the file read/write Text or Binary file functions that need the separate Open/Create/Replace File function. LabVIEW will automatically lock the file once you open it.

 


That is what I tried, and I was able to open the Same File with multiple LabVIEW Instances.

I tested reading a number incrementing it and writing it back. 2 Application each looped 1000 times and waited 10 ms between loops. At the end I did not at all increment by 2000 and without using Deny Access Function I also got no denied access errors which I now can use to wait for other applications to finish first.

 

 

But maybe I did something strange 🙂 started LabVIEW 8 Days ago.

 

0 Kudos
Message 4 of 6
(1,099 Views)

@PaulPascher wrote:

@RTSLVU wrote:

If you use the file read/write Text or Binary file functions that need the separate Open/Create/Replace File function. LabVIEW will automatically lock the file once you open it.

 


That is what I tried, and I was able to open the Same File with multiple LabVIEW Instances.

I tested reading a number incrementing it and writing it back. 2 Application each looped 1000 times and waited 10 ms between loops. At the end I did not at all increment by 2000 and without using Deny Access Function I also got no denied access errors which I now can use to wait for other applications to finish first.

 

 

But maybe I did something strange 🙂 started LabVIEW 8 Days ago.

 


Was that multiple VI's running in the LabVIEW development environment?

 

As I would expect that to happen in the development environment, as it's the "same program" (labvew.exe) accessing the same file from Windows' point of view...

(All vi's in the development environment are running in the same instance of LabVIEW.exe) 

 

But two Windows executables should block each other from accessing the same file while the other has it open.

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 6
(1,095 Views)

@PaulPascher wrote:
But maybe I did something strange 🙂 started LabVIEW 8 Days ago.

This is the point in history where it would help to attach some simplified code that reproduces the problem.

 

Your described example seems simple enough for us to test!

 

When you open the file, what are the access options? (read/write, read-only, write-only). Do you keep the ref open for the duration of the run? Do you want to deny all access or just write access?

What is your definition of "LabVIEW instance"? (Just two toplevel VIs running in the same LabVEW instance? Something else?)

 

What are you actually trying to do? Maybe there is a much better solution overall!

 

0 Kudos
Message 6 of 6
(1,085 Views)