LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to lock a file so that users can NOT open while Testing?

Hello World:

 

I'm sure there is a way but I can not think of a good solution right now.

 

I'm writing to a file.csv every 2 seconds for about 10 hours or more.

 

If a user opens the file to view, then my program in Labview will crash

because is being used.

 

How would you solve this problem?

 

thank you very much...for your help...

 

\\carlos

 

0 Kudos
Message 1 of 9
(6,136 Views)

Look up the function to Get and Set File permissions.  This will allow you to lock the file when you start and unlock it when your finished.  =o)

 

Here's the sample from the help file:

 

The Set Permissions function includes a permissions input that allows you to control access to files and directories that you create. To define the permissions you want to set, you can wire the permissions output of the Get Permissions function to the permissions input of the Set Permissions function, or you can wire a constant or a control.

 

The 9 bits that the permissions parameter uses are divided into three sets: user, group, and others. Each set is divided into three permission categories: read, write, and execute. Read determines if members of a set can read a file or directory. Write determines if members of a set can write data to a file or directory. Execute determines if members of a set can execute the file. A 1 in the bit grants permission.

For example, the following illustration shows how to grant a user permission to read from, write to, and execute a file, and deny permission from the other two sets.

 

Octal format shortens each three-bit group within the parameter to a single octal value. (Windows) For example, to make a file read-only, enter the octal value 200, which corresponds to the binary representation 10000000. (Linux) To grant users read, write, and execute permissions, enter the octal value 700, which corresponds to the binary value 111000000.

0 Kudos
Message 2 of 9
(6,130 Views)

Hello Eric:

 

I've tried that but if I lock it, then I can not write to it.

I'm writing every 10 seconds for about 10 hours.

 

If I

unlock to write and then lock

unlock to write and then lock

etc...

 

There is still a chance that a user will open the file...

while I'm writing to it...

 

thanks,

 

\\carlos

 

0 Kudos
Message 3 of 9
(6,098 Views)

Could you could save the file to a temporary directory with an obscure filename that would be hard for users to find, then move and rename it when you finish writing to the file?

 

Also, what's the error you get when the user opens the file while you're writing to it?  I assume you are opening a reference to the file once, not re-opening the file every time you need to write to it.

0 Kudos
Message 4 of 9
(6,082 Views)

Hi Diego,

Have you tried just setting the properties of the file on all other users' computers to 'Read Only' in windows?

Regards,

John McLaughlin
Academic Account Manager
National Instruments UK & Ireland
0 Kudos
Message 5 of 9
(6,074 Views)

Hello Nathan:

 

That is a possible solution.

Maybe I can put a copy that the user can open and see.

 

I'm using the NI "Write to Spreadsheet File" Vi which opens and closes the reference each time.

 

The error I get is the "Unable to write to file" because the file is open.

 

thank you,

 

\\carlos

 

 

0 Kudos
Message 6 of 9
(6,059 Views)

Hello John:

 

If I set the properties to read only, then I can not write to it...

 

thanks,

 

\\carlos

 

0 Kudos
Message 7 of 9
(6,057 Views)

 


Diego2000 wrote: 

I'm using the NI "Write to Spreadsheet File" Vi which opens and closes the reference each time.


If you rewrite your code to open the file once at the beginning and don't close it until you finish writing, the problem will probably go away.  You can open "Write to Spreadsheet File" and copy the individual sections into your code.  This will also speed up writing to the file.

 

0 Kudos
Message 8 of 9
(6,056 Views)

Why couldn't you display (graph, numberics in a table?, array of ?) the data on the program then the user would not have to open a file to see the data? 

 

I would also do nathan said and make a temp file for recording and you could ever hour or so update the viewable file.

 

 

0 Kudos
Message 9 of 9
(6,038 Views)