Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Write New Lines to the microSD-Card


  • Please log in to reply
2 replies to this topic

#1 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 07 November 2012 - 07:56 AM

Hi,

i want to write all Netduino Error / Crashes to the microSD-Card. My Problem is, when the Error file is too big, the netduzino runs out of memory.

How can i fix it or is there a better way?

Public Function Log_Error(ByVal NetduinoError As String)
        Dim filestream As New IO.FileStream("\SD\ERRORS\ERROR.log", IO.FileMode.Open)
        Dim Streamreader As New IO.StreamReader(filestream)
        Dim x As String = Streamreader.ReadToEnd
        Streamreader.Close()
        filestream.Close()
        x = x & vbcrlf & Date.Now & ": " & NetduinoError
        Dim filestream2 As New IO.FileStream("SD\ERRORS\ERROR.log", IO.FileMode.Append, IO.FileAccess.Write, IO.FileShare.None)
        Dim streamWriter As New IO.StreamWriter(filestream2)
        streamWriter.WriteLine(x)
        streamWriter.Close()
        filestream2.Close()
        Return NetduinoError
    End Function
End Module

And a little Question more ^^. It dont understand "vbcrlf" (for a new line)

thx & mfg

gfc

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 07 November 2012 - 08:05 AM

Hi gfc,

I would avoid doing this:
Streamreader.ReadToEnd

It's better to read and write a line at a time (or a chunk of bytes over and over again).

Also, if you're opening the file for Append...are you sure you want to be writing out the entire text again (including what's already there)?

Chris

#3 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 07 November 2012 - 09:49 AM

Chris Walker: ...and write a line...


=D thats a good idea.
I changed the code to:

Module LOG

    Public Function Log_Error(ByVal NetduinoError As String)
        Dim time As String
        If Microsoft.SPOT.Hardware.PowerState.Uptime.Days = 0 Then
            time = ("Uptime: " + Microsoft.SPOT.Hardware.PowerState.Uptime.ToString())
        Else
            time = ("Uptime: " + Microsoft.SPOT.Hardware.PowerState.Uptime.Days.ToString() + " days, " + Microsoft.SPOT.Hardware.PowerState.Uptime.ToString())
        End If
        Dim filestream2 As New IO.FileStream("SD\ERRORS\ERROR.log", IO.FileMode.Append, IO.FileAccess.Write, IO.FileShare.None)
        Dim streamWriter As New IO.StreamWriter(filestream2)
        streamWriter.WriteLine(time & " = " & NetduinoError)
        streamWriter.Close()
        filestream2.Close()
        Return NetduinoError
    End Function
End Module
I think, that it write directly a new line, without to open the complete file. I testet it only with some errors and it work correctly. But i dont know, how it work, when the file is bigger that 700Bytes :S(like 23MBytes)

mfg & thx

gfc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.