Shop OBEX P1 Docs P2 Docs Learn Events
Kye's fat driver - how to handle errors? — Parallax Forums

Kye's fat driver - how to handle errors?

pik33pik33 Posts: 2,397
edited 2012-06-17 09:37 in Propeller 1
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:
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

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-06-17 01:10
    I used this code to print an error and then hang the program if a file is not found
    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 program
    

    Is this what you need to do?
  • pik33pik33 Posts: 2,397
    edited 2012-06-17 03:18
    Yes, I didn't notice that function in the file so I patched it with my own.

    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:
    pub geterror
    result:=errorNumberFlag
    
    pub reseterror
    errornumberflag:=0
    

    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...
  • KyeKye Posts: 2,200
    edited 2012-06-17 09:37
    The function "fat.partitionError" returns an non zero where the non zero number is the error code which you can match to an error code in the top constant section of the driver. After you call the fat.partitionError function it clears the error. So, it's like the two functions you just added. But all in one.

    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... 
    
    
Sign In or Register to comment.