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.

Novice Alex

Member Since 27 Feb 2011
Offline Last Active Nov 28 2012 11:12 PM
-----

Topics I've Started

SD File corrupted

24 September 2012 - 02:56 PM

Hi Guys,

I have done up a commercial project and now doing the "burn test".
This project suppose to do data logging of the fuel consumption from different flow meters on a 5 mins interval.
However, I found that randomly the log file could be corrupted and it will cause the whole N+ to hang when accessing it.
I have tried to access the SD card using my PC and can see that that particular "problem" file exists but I am not able to access it and I can't delete it from my PC. So the only way is to reformat my SD card and start fresh. This gives me some sense of "uncertainty".

Does anyone know how can we handle such cases to avoid the N+ to hang? By the way, when I say hang, it means not even when I short the reset pin to ground or press the reset can restart N+, the only way is to power it down completely.

Below is my SD card class library.
Imports System.IO
Imports SecretLabs.NETMF.Hardware.Netduino
Imports SecretLabs.NETMF.Hardware
Imports Microsoft.SPOT


Public Class cSDCard
#Region "Enumeration"

#End Region

#Region "Declaration"
    Public Shared Event LastError(ex As Exception)
    Public Shared Event SDEject()
    Private Shared m_bSDEjected As Boolean = True
#End Region

#Region "Property"
    Public Shared Property SD_Ejected() As Boolean
        Get
            Return m_bSDEjected
        End Get
        Set(value As Boolean)
            m_bSDEjected = value
        End Set
    End Property

#End Region

#Region "Method"
    Public Shared Function MountSD() As Boolean
        MountSD = False
        SD_Ejected = True
        Try
            SecretLabs.NETMF.IO.StorageDevice.MountSD("SD", Microsoft.SPOT.Hardware.SPI.SPI_module.SPI2, 21, 57)
            Dim dirinfo As New DirectoryInfo("\SD")
            If (dirinfo.Exists) Then
                MountSD = True
                SD_Ejected = False
            End If
        Catch ex As Exception
            SD_Ejected = True
        End Try
    End Function

    Public Shared Function UnMountSD() As Boolean
        Try
            If SD_Ejected = True Then
                Exit Function
            End If

            SecretLabs.NETMF.IO.StorageDevice.Unmount("SD")
        Catch ex As Exception

        End Try
    End Function

    Public Shared Function ReadFile(sFilename As String, ByRef sContent As String, Optional bReadLastLineOnly As Boolean = False) As Boolean
        ReadFile = False
        Try
            Dim lFileSize As Long = 0
            Dim sTmp As String = ""
            sContent = ""
            If SD_Ejected = True Then
                Exit Function
            End If

            If File.Exists(sFilename) Then
                Dim myFile As New StreamReader(New FileStream(sFilename, FileMode.Open, FileAccess.Read))
                If bReadLastLineOnly = True Then
                    While (1)
                        sTmp = myFile.ReadLine
                        If Not sTmp Is Nothing Then
                            sContent = sTmp
                        Else
                            Exit While
                        End If
                    End While
                Else
                    sContent = myFile.ReadToEnd
                End If
                myFile.Close()
            Else
                Debug.Print(sFilename & " not found!!!")
            End If

            ReadFile = True
        Catch ex As Exception
            RaiseEvent LastError(ex)
        End Try
    End Function

    Public Shared Function WriteFile(sFilename As String, sContent As String, Optional bAppend As Boolean = True) As Boolean

        WriteFile = False
        Try

            If SD_Ejected = True Then
                Exit Function
            End If

            Dim myFile As StreamWriter

            If bAppend = True Then
                myFile = New StreamWriter(New FileStream(sFilename, FileMode.OpenOrCreate, FileAccess.Write))
            Else
                DeleteFile(sFilename)
                myFile = New StreamWriter(New FileStream(sFilename, FileMode.CreateNew, FileAccess.Write))
            End If
            myFile.WriteLine(sContent)
            myFile.Close()

            WriteFile = True
        Catch ex As Exception
            RaiseEvent LastError(ex)
        End Try
    End Function

    Public Shared Function DeleteFile(sFilename As String) As Boolean
        DeleteFile = False
        Try

            If SD_Ejected = True Then
                Exit Function
            End If

            If File.Exists(sFilename) Then
                File.Delete(sFilename)
            End If
            DeleteFile = True
        Catch ex As Exception
            RaiseEvent LastError(ex)
        End Try
    End Function
#End Region
End Class

Thanks in advance.

Regards,
Alex Chan

How to debug program without using VS?

13 September 2012 - 02:08 PM

Hi Guys,

I have completed my coding and allow my program runs for a few days. But recently I realise that after around 3 days of running, N+ will hang. Even the external watchdog is not able to reset it. In fact, I even try to ground the RESET pin directly still no good. Lastly I have no choice but to power it off and power it up again to consider as reset. This is no good for any commercial project.

Now I need to know if I can do the debug statements printout like "Debug.writeline" in the "Immediate window" in VS. I thought of using the USB as the comm port and hock up to hyper terminal to receive the debug printout. Is it possible? I don't wish to enable the VS all the day as I am using my laptop for our development.

Please advise.

Regards,
Novice Alex

Protect or encrypt program Code in N+

04 September 2012 - 08:46 AM

Hi Chris, Just like to know what are the ways to encrypt our program code in the N+ to prevent others from decrypt it? I have completed a commercial project and would like to protect the program. Please advise. Regards, Novice Alex

PWM Setup

27 August 2012 - 04:03 AM

Hi Guys,

I am trying to setup a PWM to generate constant pulse for my monitoring project.
Below are the codes.

Public WithEvents Supply As InterruptPort
Public PWM_Supply As New SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5)

Supply = New InterruptPort(Pins.GPIO_PIN_D0, False, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh)

Dim period As UInt32 = 1 * 1000 * 1000 '1 seconds
Dim duration As UInt32 = 5 * 100 * 1000 '0.5 seconds
PWM_Supply.SetPulse(period, duration)

After executing the last command "SetPulse", the below exception will be trigger
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.PWM.dll

Can anyone highlight the problem in this declaration?
Thanks in advance.

Regards,
Novice Alex

Ways to read large (>12Kb) text files from SD card

24 August 2012 - 02:02 PM

Hi Guys, Currently I have developed a near to completed application on the N+ using Netduino firmware (to get the extra RAM). But only today, I realise N+ has a problem reading text file (with around 500 records) of size around 12Kb. I need to read back for historical reporting on daily basis. I am using the streamreader.readtoend method, but it will throw SystemOutofMemory. I also tried using the pre-define size buffer(1024) to read block by block, but still meet the same exception. I also tried using the readline method together with stringbuilder library to join each readline returns. But still hit the same exception. Then I finally give up. I have to reduce my sampling interval to ensure the daily file size is around 6K instead, then everything goes well. Just like to check anyone out there has a better idea how to handle large text file data log files? Thanks in advance. Regards, Novice Alex

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.