Announcement

Collapse
No announcement yet.

File error 24

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File error 24

    I am trying to make a simple logging application, which would store chunks of data to file on the SD card. The procedure works OK and I can read the file in the card reader on my laptop. However, occasionally I get the file error 24, just after I perform the File_Close command and the last block of data is not stored. Also, the file_Close function returns the value 0 (not closed). As it turned out, this happens always when the size of the file after the write would be a multiple of 512 (512, 1024, 12800, etc).

    Is there a problem with the file closing in uLCD-32PT, if the data fills the sector? I have R25 PmmC installed.

    I am using a 2Gb Kingston SD card, so there is also a chance that this particular model is not of the best quality. I have tried this with another card of the same type and the behaviour is the same.



    I have written a short debug application to highlight the problem. The procedure is appending 200 bytes of data, until it comes to the file size of 12800 bytes (25*512), when new appends are rejected. Changing the packet size will stop execution at different file size, but it will always be a multiple of 512.


    Code:
     #platform "uLCD-32PT_GFX2"
    #STACK 500 
    func main()
    var SizeHi,SizeLo,iteration:=0,res,fHandle,filename,DataBuff,pbDataBuff,PacketSize;
    DataBuff := mem_AllocV(600) ; //create generic buffer
    pbDataBuff:=str_Ptr(DataBuff) ;
    if(!file_Mount()) //mount disk
    putstr("Disk not mounted" ) ;
    while(!file_Mount()) ;
    endif
    filename:="test1014.bmp"; //file name
    if(file_Exists(filename)) file_Erase(filename) ; //erase old file
    PacketSize:=200; //size of the packet
    repeat
    fHandle:=file_Open(filename,'a') ; //open file for appending
    txt_MoveCursor(0,0) ; //debug
    file_Size(fHandle,&SizeHi,&SizeLo) ; //debug
    print("File size before W: ",SizeLo,"\n" ) ; //debug
    res:=file_Write(pbDataBuff,PacketSize,fHandle) ; //append data packet to file
    print("Bytes written: ",res,"\n" ) ; //debug
    print("Write error: ",file_Error(),"\n" ) ; //debug
    file_Size(fHandle,&SizeHi,&SizeLo) ; //debug
    print("File size after W: ",SizeLo,"\n" ) ; //debug
    res:=file_Close(fHandle) ; //close file
    print("File closed: ",res,"\n" ) ; //debug
    print("Close error: ",file_Error(),"\n" ) ; //debug
    iteration++; //debug
    print("loop iteration: ",iteration,"\n" ) ; //debug
    //pause is just for easier debugging, same behaviour with all settings
    pause(100) ;
    until((SizeLo>32000) || iteration>=1000) ;
    repeat
    forever
    endfunc

  • #2


    Thank you for the bug report.

    Indeed there is a problem when saving a file that has even sector boundary address.

    Currently, there is no workaround for this, other than ensuring that sector alignment does not occur. The problem will only occur on aligned sectors,
    resulting in no proper closure of file (file size will not be written, leaving
    the most recent file size if opened for append, or zero for a file that was
    opened for writing)

    It will be fixed for the next release.
    Regards,
    Dave

    Comment


    • #3


      Thanks for the prompt reply!

      I will make a software workaround by appending an extra byte, whenever the new file length is critical. And of course, I am looking forward to the new PmmC release.

      Comment

      Working...
      X