LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

problem closing file using ref number

I am trying to write data (appending) to a text file
I open the file using the dialog and the file open
Then I write to the file using the ref number provided by the file open (this should append)
I do this several times.
The ref number is a valid number (0), and is passed properly from the open to the write and to the close.
When I try to close the file I get the following error.
 
 
LabVIEW:  An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.
=========================
NI-488:  Command requires GPIB Controller to be Controller-In-Charge.
 
I don't understand how the file could have an inappropriate character...open without error...write without error...and then present this error when closing.
 
the error is produced at closing.
 
Humming comming to a dead stop...unless you can help.
Thanks
0 Kudos
Message 1 of 9
(3,377 Views)
What part do you "do several times"? The opening and writing and closing, or the opening and writing, or just the writing. By the way, "0" is not a valid refnum. Also, writing to the file will not automatically append. You have to set the file position to the end of the file. Otherwise it starts writing at the beginning.

Posting your code will help. You, not your hummer.
0 Kudos
Message 2 of 9
(3,372 Views)

Here is the vi. 

Thanks

Hummer

0 Kudos
Message 3 of 9
(3,370 Views)
I ran your VI and did not get an error. I clicked "open", then "write", and then "close". No error.

A couple of points:
  1. Normally when you use an event structure to handle buttons you place the button inside the event case so that it can be read and the button is properly reset.
  2. You have a double tunnel at the event structure for the error out wire:

  3. The proper way to handle the "Stop" button is to create an event case for it. As it is, the VI will not stop unless you press one of the other buttons to trigger the event structure. (Is this perhaps what you're doing?)
  4. As I indicated, your code will not append text. You need to set the file position to the end of the file before you write. Otherwise, it just writes the text starting at the beginning of the file.


Message Edited by smercurio_fc on 07-02-2008 10:10 AM
0 Kudos
Message 4 of 9
(3,365 Views)

Got it...

I fixed the error connection....moved the buttons...(doooooppp!) and ran it again...with the same error.

When you ran the vi, did it ask you for a file spec and when it wrote to the file did it write correctly...

I meant to open a new file (not appending to an old file)

Write text to the file using the write button.

Type some more text and then write again...(the write says it will add to the end of the file if the reference number is used...so that is what I ment by appending.)

Then press the close button.

We have just installed the new version on the computer so it may be a permissions thing here...

I'll check that and let you know.

Thanks for your help.

0 Kudos
Message 5 of 9
(3,358 Views)

The problem is your open/create/replace file VI.  It needs some of its constants wired in.  The default is Open, if you select a non-existent file, it creates error 7 

"Error 7 occurred at Open/Create/Replace File in just%20a%20test[1].vi

Possible reason(s):

LabVIEW:  File not found. The file might have been moved or deleted, or the file path might be incorrectly formatted for the operating system. For example, use \ as path separators on Windows, : on Mac OS, and / on Linux. Verify that the path is correct using the command prompt or file explorer.
========================="

This error needs to be handled.  And the double error tunnel is messing that up.

Add a constant and choose, open or create, or replace or create.



Message Edited by Ravens Fan on 07-02-2008 11:53 AM
0 Kudos
Message 6 of 9
(3,353 Views)
When I clicked the "open" button I got a dialog box asking me for the file. I entered a filename.
When I clicked the "write" button it wrote the contents to the file (at the beginning). I verified the contents were written with an external program.
When I clicked the "write" button again it wrote the new contents to the file (where it left off). I verified the contents were written with the same external program.
When I clicked the "close" button the file was closed with no errors.

The only time I got the error is when I had to click the "close" button again after I had already closed the file in order to get the event case to trigger so that the loop would stop because there was no event case handling the "Stop" button.

You said "(the write says it will add to the end of the file if the reference number is used...so that is what I ment by appending.)". That's not what the LabVIEW Help says. The LabVIEW Help says this:
Writes a string of characters or an array of strings as lines to a file. If a path is wired to the file (use dialog) input, the function opens or creates the file before writing to it and replaces any previous file contents. If a file refnum is wired to the file (use dialog) input, writing begins at the current file position. To append to an existing file, set the file position to the end of the file by using the Set File Position function. Use the Set File Position function if you need to perform random access.
Note that it says that if you use a file refnum it will write at the current file position. When you open the file the file position is at the beginning. Thus, the first write will be at the beginning of the file. Subsequent writes will continue where the last write ended.


EDIT: Seeing Raven's post I should have pointed out that I was working with an existing file. I missed that. Thanks for spotting that.


Message Edited by smercurio_fc on 07-02-2008 10:56 AM
0 Kudos
Message 7 of 9
(3,347 Views)

Perfect...

Ravensfan is exactly right.  I changed the open to open or create (like I have remembered to do before on other occations...but not this one...) and all works fine.

Thanks ... this makes my afternoon look very promising.

Humming along once again.

0 Kudos
Message 8 of 9
(3,346 Views)

Here is the final version with all corrections made.

It includes writing the text that is typed ... appending a crlf to go to a new line in the text file

It then clears the text file.

AND it closes correctly.

A simple example that I appreciate very much having all the help with.

Really Hummin' now.

0 Kudos
Message 9 of 9
(3,322 Views)