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

Netduino TelnetServer bytes-error


  • Please log in to reply
8 replies to this topic

#1 gfcwfzkm

gfcwfzkm

    Advanced Member

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

Posted 17 September 2012 - 08:47 AM

Hi Community,

i have a little Problem with my Netduino+ - TelnetServer. I using the Toolbox.NETMF.dll and the Toolbox.NETMF.NET.dll for the Telnetserver.

My Problem:
Always, when i try to turn a LED on off (over Telnet) then i become bytes-errors:
Eine Ausnahme (erste Chance) des Typs "System.Net.Sockets.SocketException" ist in Microsoft.SPOT.Net.dll aufgetreten.
Failed allocation for 136 blocks, 1632 bytes
or:
Eine Ausnahme (erste Chance) des Typs "System.Net.Sockets.SocketException" ist in Microsoft.SPOT.Net.dll aufgetreten.
Failed allocation for 116 blocks, 1392 bytes

Always these errors. But only, when i use my Telnet-Control Program. When i use CMD>Telnet, then it works without problem, but i need a GUI.
Here is my LED_Test.vb from the netduino-server:
Imports System
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports Toolbox.NETMF
Imports Toolbox.NETMF.NET
Imports Microsoft.VisualBasic
Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Namespace Programs

    Public Module LED_Test

        Dim led1 As OutputPort = New OutputPort(Pins.GPIO_PIN_D0, False)
        Dim led2 As OutputPort = New OutputPort(Pins.GPIO_PIN_D2, False)
        Dim led3 As OutputPort = New OutputPort(Pins.GPIO_PIN_D4, False)

        Public Sub Bind(ByVal Shell As ShellCore)
            AddHandler Shell.Empfangen, AddressOf Shell_OnCommandReceived
        End Sub

        Public Sub Unbind(ByVal Shell As ShellCore)
            RemoveHandler Shell.Empfangen, AddressOf Shell_OnCommandReceived
        End Sub

        Public Sub Shell_OnCommandReceived(ByVal Shell As ShellCore, ByVal Arguments() As String, ByRef SuspressError As Boolean, ByVal Time As DateTime)
            Dim command As String = Arguments(0).ToUpper()
            Dim lol As String = command
            Debug.Print(command & "|" & lol)
            If lol.Substring(0, 3) = "LED" Then
                LED_Test.Start(command, Shell.Telnetserver)
                SuspressError = True
            ElseIf command = "HELP" Then
                If Arguments.Length = 1 Then
                    Shell.Telnetserver.Print("LED[NUMMER]=[1/0]                  Interactive Output Demo")
                    SuspressError = True
                Else : End If
            End If
        End Sub

        Public Sub Start(ByVal command As String, ByVal Server As TelnetServer)
            command = command.Substring(3)
            Debug.Print(command)
            Dim status As String() = command.Split("=")
            Dim Output As String = status(0)
            Dim on_off As String = status(1)
            Debug.Print(Output)
            Debug.Print(on_off)
            Select Case Output
                Case "1"
                    If on_off = "1" Then
                        led1.Write(True)
                        Server.Print("LED1=1")
                    ElseIf on_off = "0" Then
                        led1.Write(False)
                        Server.Print("LED1=0")

                    Else : End If
                Case "2"
                    If on_off = "1" Then
                        led2.Write(True)
                        Server.Print("LED2=1")
                    ElseIf on_off = "0" Then
                        led2.Write(False)
                        Server.Print("LED2=0")
                    Else : End If
                Case "3"
                    If on_off = "1" Then
                        led3.Write(True)
                        Server.Print("LED3=1")
                    ElseIf on_off = "0" Then
                        led3.Write(False)
                        Server.Print("LED3=0")
                    Else : End If
            End Select
        End Sub
    End Module
End Namespace

And Here a little Piece of my "SEND-Class" of my Telnet-Client:
Public Sub Senden(ByVal text As String)
        Dim SendBytes As [Byte]() = Encoding.ASCII.GetBytes(text & vbCrLf)
        tnSocket.Send(SendBytes, SendBytes.Length, SocketFlags.None)
    End Sub
And the listen-code
Public Sub Listen()

        Dim NumBytes As Integer = 0
        Dim RecvBytes(511) As [Byte]
        Do While tnSocket.Connected = True
            Do
                NumBytes = tnSocket.Receive(RecvBytes, RecvBytes.Length, 0)
                RecvString = RecvString + Encoding.ASCII.GetString(RecvBytes, 0, NumBytes)
            Loop While NumBytes = 512
            'RichTextBox1.Text = RecvString & vbCrLf
            Me.Invoke(New DAddItem(AddressOf AddItem), RecvString)
            Me.Invoke(New DAddItem(AddressOf Steuerung), RecvString)
            Debug.Print("listening")
            Wait(1000)
        Loop
        Debug.Print("Connection lost")

    End Sub

I just tried to find the error, but i dont understand it :(

need little help please

thx & mfg

gfcwfzkm

EDIT\> im not sure, but i think, that the error come allways, when im under 20kB Free RAM.
When i disconnect me, the program take allways ~0.5kB RAM. How i can fix that?

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 17 September 2012 - 11:58 AM

It looks like a memory issue indeed. Try to remove assemblies you don't use, maybe that will help?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 gfcwfzkm

gfcwfzkm

    Advanced Member

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

Posted 17 September 2012 - 01:53 PM

i just tried that.
I just removed all Debug.Print-Commands, but then i toke 3kB for each new connection :S

Is there a memorymanagement-code for netduino, like that for WindowsForms? :

Public Class MemoryManagement

    Private Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" ( _
      ByVal process As IntPtr, _
      ByVal minimumWorkingSetSize As Integer, _
      ByVal maximumWorkingSetSize As Integer) As Integer

    Public Shared Sub FlushMemory()
        Call Module1.Write("FlushMemory...")
        GC.Collect()
        GC.WaitForPendingFinalizers()
        If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
            SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
        End If
        Call Module1.Write("Erledigt")
    End Sub
End Class

is there something like that for Netduino+ ?

mfg & thx and sorry again for the false topic / my mistake :(

gfcwfzkm

#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 17 September 2012 - 02:30 PM

There is Debug.GC(true); to initiate the garbage collector. Maybe that helps?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#5 gfcwfzkm

gfcwfzkm

    Advanced Member

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

Posted 18 September 2012 - 07:21 AM

it dont make many: from 45.14kB -> 44.64kB -> 44.17kB It take every new "Listening" 0.5kB ram. In the Microsoft-Emulator, with the "Debug.GC(TRUE)" code, it print this: GC: 1msec 291420 bytes used, 3902664 bytes available Type 0F (STRING ): 288 bytes Type 11 (CLASS ): 1464 bytes Type 12 (VALUETYPE ): 156 bytes Type 13 (SZARRAY ): 828 bytes Type 03 (U1 ): 156 bytes Type 04 (CHAR ): 276 bytes Type 07 (I4 ): 36 bytes Type 11 (CLASS ): 360 bytes Type 15 (FREEBLOCK ): 3902664 bytes Type 16 (CACHEDBLOCK ): 72 bytes Type 17 (ASSEMBLY ): 16380 bytes Type 18 (WEAKCLASS ): 48 bytes Type 1B (DELEGATE_HEAD ): 396 bytes Type 1C (DELEGATELIST_HEAD ): 132 bytes Type 1D (OBJECT_TO_EVENT ): 96 bytes Type 1E (BINARY_BLOB_HEAD ): 268296 bytes Type 1F (THREAD ): 372 bytes Type 20 (SUBTHREAD ): 48 bytes Type 21 (STACK_FRAME ): 696 bytes Type 27 (FINALIZER_HEAD ): 96 bytes Type 28 (MEMORY_STREAM_HEAD ): 36 bytes Type 29 (MEMORY_STREAM_DATA ): 396 bytes Type 31 (IO_PORT ): 144 bytes Type 34 (APPDOMAIN_HEAD ): 72 bytes Type 36 (APPDOMAIN_ASSEMBLY ): 1404 bytes GC: performing heap compaction... 3902664 But in the Netduino come nothing. i just tried "Debug.Print(Debug.GC(True)), then it Print: 42240, 46644, 42360 mfg gfc

#6 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 18 September 2012 - 08:05 AM

Quick question, do you have Visual Studio Express or Visual Studio Professional? If it's the latter, you can save some more memory by not adding the toolbox dll-files as reference, but by adding the project files and remove classes you don't use. I know the VB-example of the telnet server already had quick memory issues, I solved this by removing some of the telnet apps. On a micro framework, it's always recommended to not embed unused code.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#7 gfcwfzkm

gfcwfzkm

    Advanced Member

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

Posted 18 September 2012 - 08:49 AM

At the moment, i use for my TelnetServer Visual Basic Express. But at home (im not sure, i check it later) i have Visual Studio Ultimate. Is VisualStudio Professional TestVersion enough, to add the project files, and then work with normal VisualBasic Express? I just removed many apps. theres only ShellCore, Auth, LED_Test and BasicCommands. mfg gfc

#8 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 18 September 2012 - 09:12 AM

Is VisualStudio Professional TestVersion enough, to add the project files, and then work with normal VisualBasic Express?

I think so, it's worth the try :)

The good thing of the Professional Edition is that it's possible to combine VB.NET and C# projects in one solution. A feature that's not available with the Express Edition.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#9 gfcwfzkm

gfcwfzkm

    Advanced Member

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

Posted 19 September 2012 - 06:46 AM

It works, thanks =) mfg gfcwfzkm




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.