beautypg.com

Fileopen, Enter fileopen parameters – Campbell Scientific CR9000X Measurement and Control System User Manual

Page 385

background image

Section 9. Program Control Instructions

FileOpen

Used to open an ASCII text file or a binary file for writing or reading

Syntax

FileHandle = FileOpen("Device:FileName", "Mode", SeekPoint)

Remarks

The FileOpen function returns a FileHandle, which can then be used by
subsequent file read/write functions (FileWrite, FileRead, FileReadLine,
FileClose). The FileHandle variable must be declared as a Long variable type.
The file to be read from or written to can be either an ASCII text file or a
binary file. If FileOpen fails, zero (0) will be returned.

Multiple reads or writes (prior to a FileClose for the FileHandle) begin where
the previous file operation left off. When a FileClose instruction is executed
for the FileHandle, the FileHandle is deleted.

If the file is opened with a mode that specifies ASCII, when a Chr(10) (line
feed) is encountered, a Chr(13) (carriage return) is inserted before the line
feed.

The MoveBytes instruction should be used to move floats into a string variable
if TOB1 binary files are being written.

Parameter

Enter FILEOPEN

PARAMETERS

Device:FileName
String in quotes

The FileName parameter is used to specify the Device and FileName for the file
written to or read from. FileName must be enclosed in quotes. It is entered in the
format of "Device:FileName" where Device is CPU or CRD (compact flash card).

Code

Action to be taken

"a"

Append to ASCII file at EOF (write). Set SeekPoint to -1 to append to
end of file, or specify a value to begin writing other than end of file

"ab"

Append to binary file at EOF (write). Set SeekPoint to -1 to append to
end of file, or specify a value to begin writing other than end of file.

"a+"

Append to ASCII file at EOF (read/write). Set SeekPoint to -1 to append
to end of file, or specify a value to begin writing other than end of file.

"a+b"

Append to binary file at EOF (read/write). Set SeekPoint to -1 to append
to end of file, or specify a value to begin writing other than end of file.

"r"

Open ASCII file for reading at SeekPoint (read).

"rb"

Open binary file for reading at SeekPoint (read).

"r+"

Open ASCII file for update at SeekPoint (read/write).

Mode
String Variable

"r+b"

Open binary file for update at SeekPoint (read/write).

"w"

Open/overwrite ASCII file (write). SeekPoint is not valid; leave at 0

"wb"

Open/overwrite binary file (write). SeekPoint is not valid; leave at 0

"w+"

Open/overwrite ASCII file (read/write). SeekPoint is not valid; leave at 0.

"w+b"

Open/overwrite binary file (read/write). SeekPoint is not valid; leave at 0.

SeekPoint
Variable

Specifies the byte position to begin reading from or writing to when the file is
opened. The value is in bytes, and the read or write begins after the specified
SeekPoint. For instance, if 100 is entered, the read or write begins at byte 101. If 0 is
entered and a file is being written, existing data will be overwritten. If one of the four
"a" options is being used to write data, enter -1 to append to the end of the file or
enter a value to begin at a specific byte. SeekPoint has no affect with the "w"
options, which always begin at byte 0, overwriting the existing data.

This is a blank page.

9-55