LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

File Lockout between LabVIEW Versions

I want to develop a VI that can edit a file (over a network connection), and while open create a lockout scenario that will prevent any other computers from opening and editing the file simultaneously.  To increase the complexity I will be implementing these functions on LabVIEW systems of different versions (currently 7.1 and 8.2).

 

In LabVIEW 7.1 I have been able to use the Lock Range function to reserve the whole file and can determine the file is in use when I receive a File Permission Error (Error 😎 during the File Read function.

 

In LabVIEW 8.2 the lock function is converted into the Deny Access function which does cause an Error 8 when the file is opened in both LabVIEW versions. The problem is when the file was locked out in LabVIEW 7.1 this Deny Access function causes LabVIEW to crash (Lock Range allows the File Open function without error in LabVIEW 8.2).

 

Is there a way to limit access to the file like Deny Access does (much like any Windows application exclusive access) in LabVIEW 7.1 so that an error on File Open would indicate the file is in use?  Or does anyone have an idea of a different programming algorithm that would create the file lockout.

 

-andy

0 Kudos
Message 1 of 3
(3,186 Views)

One idea as a workaround method would be to create a lock file.  I am getting the idea from the way AutoCAD creates a .dwl file as an indicator that the .dwg drawing file is locked.

 

Before a file is open, create a .lok file in the same directory that has the same name as the file of interest.  It could be empty, or it could contain some useful information that you insert such as who created the file.  Before any LV program tries to open the program for editing, check for the existence of the .lok file.  If the .lok file exists, then don't open the data file and return a message to the user.  Whichever program was able to open the data file and create the .lok file will have the responsibility of deleting it and it closes the associated datafile.

 

You would always run the risk (I remember this happening with AutoCAD) that if the program that created the .lok file crashes before it has a chance to close properly and clear the lock.  The file would be effectively locked to itself or any other program.  You would wind up with a persistent .lok file.  But you could easily delete them on your own from Windows explorer.

 

I believe Microsoft Excel basically does a similar same thing to create some locks, but it just builds a flag into the .xls file itself.  If no changes are made, it clears the flag and returns the file date back to its original file date.    If you ever notice, if you have an older xls file, as soon as you open it in Excel, the file modified date suddenly becomes the new date and time.  If you close the file without saving it, Excel reverts the modified date and time back to its original date and time.  I actually find this kind of annoying because if I am working on an Excel file and want to check out old it was, you can't check the file attributes because they've been updated.  You are forced to close without saving (thus losing any changes you made that you might have been interested in ultimately saving) so that you can check the file attributes for their original values.

0 Kudos
Message 2 of 3
(3,172 Views)
I have 8.2.1 (not 8.2) installed, but it seems to work fine on my machine.  The Deny Access funtion errors out with an error 5, indicating the file is open, if LabVIEW 7.1 opens the file (it doesn't even have to use the lock range).
0 Kudos
Message 3 of 3
(3,168 Views)