Reading from a file
in Propeller 1
I trying to read a text file to get a file name.
Just reading a simple text file with two lines in it.
Right now I would be happy just to get the first line.
FILE1000.HEX Other options
This is the output I get.
Starting Initializing SD Card System SD Card System Initialized Opening File: STARTUP.TXT File Opened File to start with:
con { timing }
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 ' use 5MHz crystal
CLK_FREQ = (_clkmode >> 6) * _xinfreq ' system freq as a constant
MS_001 = CLK_FREQ / 1_000 ' ticks in 1ms
US_001 = CLK_FREQ / 1_000_000 ' ticks in 1us
con { io pins }
sdDOpin = 1 ' Data Out Pin
sdCKpin = 2 ' Clock Pin
sdDIpin = 3 ' Data in Pin
sdCSpin = 4 ' Chip Select Pin
sdLEDpin = 17 ' Status LED pin number.
RX1 = 31 ' programming / terminal
TX1 = 30
SDA = 29 ' eeprom / i2c
SCL = 28
con { settings }
maxled = 288
obj
sd : "SD-MMC_FATEngine.spin"
time : "jm_time_80.spin"
pst : "Parallax Serial Terminal.spin"
var
byte frameFileName[13]
pub main | errorNumber, errorString, tLong
pst.Start(115200)
pst.Str(String("Starting "))
pst.Str(String("Initializing SD Card System"))
pst.Chars(pst#NL, 2)
sd.fatEngineStart(sdDOpin, sdCKpin, sdDIpin, sdCSpin, -1, -1, -1, -1, -1)
pst.Str(String("SD Card System Initialized"))
pst.Chars(pst#NL, 2)
readStartFile
pub readStartFile
openFile(string("STARTUP.TXT"))
sd.readString(@frameFileName, 14)
pst.Str(string("File to start with: "))
pst.Str(@frameFileName)
pst.Chars(pst#NL, 2)
pst.Char(frameFileName[0])
pst.Char(frameFileName[1])
pst.Char(frameFileName[2])
pst.Char(frameFileName[3])
pst.Char(frameFileName[4])
pst.Char(frameFileName[5])
pst.Char(frameFileName[6])
pst.Char(frameFileName[7])
pst.Char(frameFileName[8])
pst.Char(frameFileName[9])
pst.Char(frameFileName[10])
pst.Char(frameFileName[11])
pst.Char(frameFileName[12])
pst.Chars(pst#NL, 2)
' closeFile
'****************************************************************
'
'
'
pub OpenFile(fileName) | errorString, errorNumber
pst.Str(String("Opening File: "))
pst.Str(fileName)
pst.Chars(pst#NL, 2)
errorString := \sd.openFile(fileName, "R")
errorNumber := sd.partitionError
if(errorNumber)
pst.Str(String("Error Opening File"))
pst.Chars(pst#NL, 2)
else
pst.Str(String("File Opened"))
pst.Chars(pst#NL, 2)

Comments
As it stands, this demo allows you to set a filename string (8.3 format) and up to three, byte options. The way my configuration reader works you can add comments by using the single quote character -- these can be at the start of a line, or even after the commands.
The nice thing about using a parser like this is that you're not depending on the order of items in the file (as long as they are syntactically correct), and you can mix notes into the file using the comment character.
This is the contents of the test file I used:
Note that I'm able to use white space and comments.