sxfile
Sxfile is a file object. Use it to read, write, or execute files on the SD card.
Each sxfile instance in a program refers to a different file, so you can have multiple files open concurrently.
Spin methods
PUB Open(pFilename, mode) -- pFilename points to a null-terminated 8.3 filename (e.g., "test.spn"). mode is either "R" or "W". If mode is "R" and the specified file does not exist, this method returns 1; otherwise, this method returns 0 to indicate success and aborts if an error occurs.
PUB Close -- closes an open file. You must close files that have been opened for writing in order to flush buffers to the SD card. Closing files opened for reading is less important (actually optional).
PUB Read(ptr, n) -- read n bytes into hub memory starting at address ptr. Returns the number of bytes actually read, or -1 if the end of file is reached.
PUB Write(ptr, n) -- write n bytes from hub memory starting at address ptr.
PUB Length -- returns the length of the file. The file must first be opened for reading.
PUB Execute(mode) -- executes the file. The file must first be opened for reading. A non-0 mode causes the equivalent of a system reset before the file runs.
PUB ReadString(p, MAXLENGTH) -- reads a null-terminated string into hub memory starting at address p. If the string exceeds MAXLENGTH characters, this method aborts.
PUB ReadStringUpperCase(p, MAXLENGTH) -- similar to ReadString but converts all lower-case characters to upper-case.
PUB WriteString(p) -- writes a null-terminated string to the file (including terminating null).
PUB ReadNumber -- reads a null-terminated string representing a decimal number and returns the numeric value (e.g. if the file contains "123" followed by a null byte, this method will return 123). This method aborts if a non-numeric character is encountered.
PUB ReadByte -- reads a byte from the file.
PUB WriteByte(b) -- writes a byte to the file.
PUB ReadWord -- reads a 2-byte quantity from the file.
PUB WriteWord(w) -- writes a 2-byte quantity to the file.
PUB ReadLong -- reads a 4-byte quantity from the file.
PUB WriteLong(l) -- writes a 4-byte quantity to the file.
PUB SkipBytes(n) -- skips over the next n bytes in the file.