LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

a problem with File I/O functions

Solved!
Go to solution

smercurio_fc wrote:

Mojtaba Rezaei wrote:

Hi,

Thanks to Smercurio_fc, I found the solution. I have this problem when I use WordPad or Word to open the file. Smercurio_fc is right, it seems that these applications require exclusive access to the file.

Honestly, it makes no sense. Even while my program is running it's not using the data file. So other programs should have exclusive access to the file.


It makes perfect sense. The issue isn't whether the LabVIEW program is "using" the file - it's whether the file is open. See the following scenarios:

 

Scenario 1:

 

 

Scenario 2:

 

Message Edited by smercurio_fc on 06-04-2010 09:34 AM

But I am using 2nd scenario in my program. I close the file exactly after writing is finished.

There is something else which may be able to explain this. In my program I have a data acqisition part that has the highest priority. There is a timer card that sends a trigger pulse to initiate data acquisition process. May be during closing process labview recieves this trigger pulse and leaves the file open.

0 Kudos
Message 11 of 18
(1,117 Views)

Is your question answered (you marked Smercurio's reply #4 as the solution) or are you still having problems?

 

What version of LabVIEW are you using?  Can you post your actual VI?  You say you are using scenario #2, but your earlier screenshots look like you are using some old file functions that I don't see in my version of LV (not even under the 7.x function submenu).

 

Maybe there was an issue with the old file VI's in the way they handled file access.  I don't know.  Seeing your actual VI and knowing which version of LV you are using would go a long way in trying to figure that out.

0 Kudos
Message 12 of 18
(1,109 Views)

Ravens Fan wrote:

Is your question answered (you marked Smercurio's reply #4 as the solution) or are you still having problems?

 

What version of LabVIEW are you using?  Can you post your actual VI?  You say you are using scenario #2, but your earlier screenshots look like you are using some old file functions that I don't see in my version of LV (not even under the 7.x function submenu).

 

Maybe there was an issue with the old file VI's in the way they handled file access.  I don't know.  Seeing your actual VI and knowing which version of LV you are using would go a long way in trying to figure that out.


Yes, I got the solution. I just have to use Notpad to open my data file.

But still I am not able to open the txt file using WordPad when my program is running. (But it doesn't matter, cause I can open it with Notepad.)

My labview is 7 and if you want you can see my code. In this code I am using an Event Structure. When user hits the "report" key (which is in front panel) Event Structure executes "Report subVI" (attached), which saves data in a text file.

 

0 Kudos
Message 13 of 18
(1,103 Views)

Why is there a "Write To Spreadsheet File SubVI" sitting all by itself in the "Write Characters to File SubVI". I don't have LabVIEW 7 on this machine, but it looks like you resaved the VIs that are part of the vi.lib folder that ships with LabVIEW. Is this the case?

 

Also, how is this VI used? Are you running it once? Is it called from somewhere? Please don't tell me that you're using the Run Continuously button in the toolbar.

0 Kudos
Message 14 of 18
(1,088 Views)
Hi smercurio_f,
Alright, first the Write to Spreadsheet File subVI shouldn’t be there. I forgot to delete it. I was just going to see it when I was writing this reply and I forgot to delete it.

By the way I have changed this subVI in my program .I just added an input to it for “advisory dialog?” because when you run this subVI it keeps asking you for replacing the file (if you’ve already created it) and I didn't want to see this dialog box every time..

Back to our discussion, I have attached a demo of my code to show you the problem. This one is in LabVIEW 8 (hopefully you can open it – you said that you don’t have version 7 so I wrote this one in labview 8). Run the program and press the “Report” control key. Program creates a text file in D:\ test-rep.txt. Try and open it with WordPad when program is running to see my problem.

 

 

Download All
0 Kudos
Message 15 of 18
(1,077 Views)
And here is 3 pictures of our experimental setup and a picture of the labview program graphs, just for further clarification.
0 Kudos
Message 16 of 18
(1,075 Views)
Solution
Accepted by topic author Mojtaba Rezaei

Why do you have two file open subVI's?  One is in report subVI, which then immediately goes to Write Characters to File subVI which has another one.  When I eliminate the one in the Report subVI, everything behaves properly.  I think because you have two Opens, you have opened two references to the same file.  You wind up closing the second reference to the file in the Write Characters subVI, but the first reference is still open, and that continues to lock the file until LV ends where it then cleans up after itself and releases the resources.

 

Double check the action of your buttons.  Some of them should have a mechanical action of Latch when Released rather than Switch when pressed.  For example, Report and Stop.  When they are basically single action buttons, (do something when hit) they should be latched so they pop themselves back up once they are read in LV.  Buttons that should have a maintained state (stay on until the user turns them off) are the only buttons that should have a Switch mechanical action.  I always say "when Released" is better then "when Pressed".  It mimics the behavior or Windows buttons in that it allows a user to cancel their action by dragging the mouse off the button in case they change their mind as soon as they pressed it.

 

Also, the buttons should be in the event case that handles them so they are effectively read and returned to their original state (if Latch action) when the event case runs.

Message Edited by Ravens Fan on 06-05-2010 07:46 PM
Message 17 of 18
(1,063 Views)

Well, I guess you are right. Why did I do such a stupid thing? Maybe I was thinking that we had to open and create files separately.

So, everything makes sense now. The first subVI creates/replaces the text file and opens it as well. And then the second one opens another reference for this file. So I have two references opened for my file and just one Close subVI.  Awesome!

About the Mechanical Action of the buttons, in my program they are Latch When Released. And all of them are in the appropriate event case. It was just a quick programming here to show my problem with opening report file.

Many thanks for your help Ravens Fan.

 

 

0 Kudos
Message 18 of 18
(1,048 Views)