none
Chip write delay CF 6.5.3

    Question

  • Hello,

    Recently to reduce memory consumption on the device we started writing all file information to a SD chip(san disk, Kingston, and 4gb or 8gb). The files are mostly images (800x600 jpeg) or small text files. Also in our code we added a retry twice option if the write failed on first try. If the all writes failed we give an error to the operator.

    The problem is we are getting a lot of write errors. We've deployed about 20 separate units (Motorola mc65, Casio 9000) about 50% devices had this errors repeatedly. We've tested the software in house and can’t duplicate the issue even with the client chips. Also we had our clients reformat the chips and try again without luck.

    Any suggestions how to approach this. Is there a write delay that we are not aware of and is there a way to compensate it?

     Here is a basic code  that we have used for writting to chip.

                IoRetry = 0
    IoRetry16:
                Try
                    If sGlbStoragePath <> "" Then
                        sGlbBackupPath = sGlbStoragePath & "\Backup"
                        sGlbBackupPathChip = sGlbStoragePathChip & "\Backup"
                        If Not System.IO.Directory.Exists(sGlbBackupPath) Then
                            System.IO.Directory.CreateDirectory(sGlbBackupPath)
                        End If
                    End If
                Catch ex As Exception
                    If IoRetry = 0 Then
                        IoRetry += 1
                        GoTo IoRetry16
                    Else
                        BadChip()
                    End If
                End Try

    Friday, July 06, 2012 3:40 PM

All replies

  • Which error are you getting? Please provide exception type, error message, stack trance and other information if available.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, July 06, 2012 4:11 PM
  • sadly our logging did not have the actual exception stored, Its something i need to add if required. I do know the actual code it crashed was

    1st instance, System.IO.Directory.CreateDirectory.
    2nd instance, System.IO.File.Delete and/or System.IO.File.Move

    The way i can duplicate is lock the chip from writes. But there is no garantee its the same exception but most likely the same reason. here is the expection and stack trace for it.  

     exception "IOException" 

    stack trace:

    at System.IO.__Error.WinIOError(Int32 errorCode, String str)
       at System.IO.File.Delete(String path)
       at wincite.FrmMainMenu.LaunchApp()
       at wincite.FrmMainMenu.Timer_Tick(Object sender, EventArgs e)
       at System.Windows.Forms.Timer._WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.ApplicationThreadContext._InternalContextMessages(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at wincite.FrmMainMenu.Main()

    Friday, July 06, 2012 6:37 PM
  • This exception indicates you had issue deleting some file and that is not in the code above.

    I would guess it's not relevant to the issue. However if you make your card read only you can expect any attempt to write something to it to fail.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, July 06, 2012 7:36 PM
  • I know use the lock just to debug, I know the error is in system.IO. because all the codings only include the system.io functions like the delete, move, write or create etc. 

    These errors do not happen using the internal memory.
    My question is there a reason the sd card can be acting differently as a delay on write or low available memory or some other reason and triggering an error. Its happening to many devices that i can rule out bad chip.

    And the chips all formated and few have been tested to have a lot files to see if any corruption would happen from a pc.

    Our app runs high in memory usage (6mb to 8mb) even though the app is less then 1mb in size. I am currently trying to reduce extra items using fxcop and clr profiler (which needs another post by itself).

     
    Friday, July 06, 2012 8:27 PM
  • Since you cannot provide any information on what the actual problem is I can only speculate. I don't see how delay (if any) would cause an issue here. It would just take a bit longer to complete the operation that is. Unless you have multiple operations going on at the same time that should not be a problem.

    One known issue with storage cards is what all open file handles may be invalidated if device goes into sleep mode. That would be a problem if your application opens file(s), goes to sleep, wakes up and the attempts to access files again. Since you're retrying that should not be a problem.

    By the way, 6 to 8 MB is not that high, even by device standards.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, July 06, 2012 10:16 PM
  • Hello, I've modified the code to grab and log the exception and stack trace. Here is the code it crashed and

    IoRetry8:
                        Try
                            If System.IO.File.Exists(sGlbBackupPathChip & filename.Substring(filename.LastIndexOf("\"))) Then
                                System.IO.File.Delete(sGlbBackupPathChip & filename.Substring(filename.LastIndexOf("\")))
                            End If
                            System.IO.File.Move(filename, sGlbBackupPathChip & filename.Substring(filename.LastIndexOf("\")))
                        Catch ex As Exception
                            FileNLog("File Write Error:" & ex.Message & vbCrLf & "Stack Trace:" & ex.StackTrace, "MainScreen")
                            If IoRetry = 0 Then
                                IoRetry += 1
                                GoTo IoRetry8
                            Else
                                BadChip()
                                GoTo ChipLoadSkip
                            End If
                        End Try

    Exception:IOException
    Stack Trace:   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
       at System.IO.File.Delete(String path)
       at wincite.FrmMainMenu.LaunchApp()
       at wincite.FrmMainMenu.Timer_Tick(Object sender, EventArgs e)
       at System.Windows.Forms.Timer._WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.ApplicationThreadContext._InternalContextMessages(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at wincite.FrmMainMenu.Main()

    Hope this helps.

    Monday, July 09, 2012 9:20 PM
  • So far it seems like file exists but attempt to delete the file failed. Assuming card is not read only then that may be because file is in use.

    That's great you added logging but you should probably post the actual output from your log file.

    By the way, the best way to print exception information is to just use ToString() on the exception. That would include type, stack trace and error message.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, July 10, 2012 12:24 AM
  • Well the chip lock was my way of testing. I verified with the client they dont hav chip lock. And motorola units do not have chip lock.

    And i did post the actual log, the rest of the info on the log is irrelavant.

    and thanks for the info on ToString. :)

    Im still stuck and clients and my boss getting frustrated.

    One of my coworkers suggested write local memory then write a thread that trys over and over to write to chip. But this feels like a waste of time if the chip doesnt let you write it has to have some reason nothing is going to change that.

    Any suggestions.

    Tuesday, July 10, 2012 3:32 PM