Classes and Methods

GPL provides the File built-in class for managing files and directories. Table 19-34 summarizes the various methods available.

Table 19-34: File Class

File Class Member Type Description

File.ComputeCRC

Shared Function

Returns a CRC check code computed by reading though a file. Used to verify that a file has not been corrupted.

File.ComputeLength

Shared Function

Returns the length of a file computed by reading through a file and counting the bytes. Used to verify that a file has not been corrupted.

File.Copy        

Shared Method

Copies a single file on devices like the flash disk and ROMDISK.

File.CreateDirectory        

Shared Method

Creates a directory including any undefined directories in its path.

File.DeleteDirectory

Shared Method

Deletes a single directory, if it is empty.

File.DeleteFile

Shared Method

Deletes a single file.

File.GetDirectories

Shared Method

Returns an array of strings containing the names of directories in a directory.

File.GetFiles

Shared Method

Returns an array of strings containing the names of files in a directory.

File.Length

Shared Function

Efficiently returns the length of a file based on its directory entry.

 

GPL provides two built-in classes for accessing streams: StreamReader and StreamWriter. See Table 19-35 and Table 19-36.

Table 19-35: StreamReader Definitions

StreamReader Member Type Description

New StreamReader

Constructor Method    

Opens a file or serial port device for reading.

streamreader_obj.Close

Method

Closes a file or device.

streamreader_obj.Peek

Method

Reads a single byte but does not remove it from the input stream.

streamreader_obj.Read

Method

Reads a single byte and removes it from the input stream.

streamreader_obj.ReadLine

Method

Reads a line of bytes terminated by LF, CR, or CR-LF.

 

 

Table 19-36: StreamWriter Defnitions

StreamReader Member Type Description

New StreamWriter

Constructor Method

Opens a file or serial port device for writing.

streamwriter_obj.AutoFlush

Property

If True, automatically flushes output after every write.

streamwriter_obj.Close

Method

Closes a file or device.

streamwriter_obj.Flush

Method

Forces any pending output to occur immediately.

streamwriter_obj.NewLine

Property

Defines the line terminator characters that are appended to output by WriteLine.

streamwriter_obj.Write

Method

Writes a string or number to the output stream with no line terminator.

streamwriter_obj.WriteLine

Method

Writes a string or number to the output stream followed by a line terminator.

The same methods are used for accessing both files and serial ports. The major differences between the two are:

  1. Serial ports are normally used for communications, but files are used to save and retrieve data.
  2. Data read from files is normally available immediately, but you may need to wait to receive data from a serial port.
  3. Files have an "end of file", but serial port data can continue indefinitely.
  4. Data written to files is normally buffered for efficiency, but serial port communications are often time-critical so the output is not buffered.

GPL also provides a built-in class for performing output to the serial console or to the GDE console window. See Table 19-37.

Table 19-37: Console Class Definitions

Console Class Member Type Description

Console.Write

Shared Method

Diagnostic method that writes a number or a string to the console.

Console.WriteLine

Shared Method

Diagnostic method that writes a number or a string to the console, followed by a line feed (LF) character.