Kye's fat driver - how to handle errors?
pik33
Posts: 2,416
Most of functions included in this driver returns strings instead of error codes.
For example, this:
c:=\fat.listentry(string("test"))
returs string "TEST" if there is a file called "TEST" on disk, or it aborts and returns string "Entry Not Found", if not.
Is it any method which can tell me if this function aborted or not? I patched this driver adding two functions:
so now I can do this like
and if fat.geterror==0 I can open my file and read the data from it
How can I do this without this patch I applied to the fat driver?
For example, this:
c:=\fat.listentry(string("test"))
returs string "TEST" if there is a file called "TEST" on disk, or it aborts and returns string "Entry Not Found", if not.
Is it any method which can tell me if this function aborted or not? I patched this driver adding two functions:
pub geterror result:=errorNumberFlag pub reseterror errornumberflag:=0
so now I can do this like
fat.reseterror
c:=\fat.listentry(string("test"))
if fat.geterror<>0
vga.writeln(c)
'rest of error handling code. File doesn't exist so create one now and fill with data
and if fat.geterror==0 I can open my file and read the data from it
How can I do this without this patch I applied to the fat driver?

Comments
PUB OpenFileRead(stringptr) ' open a file for reading and display a message if it fails result := \fat.openfile(stringptr,"R") if fat.partitionerror <> 0 ' failed to find the file Text(stringptr) ' print the filename Text(result) ' print the error message repeat ' stop the programIs this what you need to do?
I want to open a file if it exists and read data from it, if not, I want to create a new one with this name and fill it with data..
I did it that way:
first added these two function to the fat driver:
and then use it:
i:=0 fat.reseterror c:=\fat.listentry(string("dmplist.dat")) if fat.geterror<>0 c:=\fat2.newfile(string("dmplist.dat"))Now I can do it like this (?)
i:=0 fat.reseterror c:=\fat.listentry(string("dmplist.dat")) if fat.partitionerror<>0 c:=\fat2.newfile(string("dmplist.dat"))and use unpatched driver...
Please see Parallax semiconductor an006 http://www.parallaxsemiconductor.com/an006.
....
So I think what you want to do is done like this:
temp := \fat.openFile(string("DMPLIST.DAT"), "R") if(fat.partitionError == fat#Entry_Not_Found) temp := \fat.newFile(string("DMPLIST.DAT")) temp := \fat.openFile(string("DMPLIST.DAT"), "W") ' Do writing stuff here.... else ' Do reading stuff here...