Main Site Documentation

Raptor Networking "This should never happen"


#1

Hi:
I am working on Raptor with the ENC28 network interface. I believe I am using the latest codebase (see versions at the end of the message).
I am attempting to get a DHCP connection, in this case to a corporate network. Estabilshing the connection works (gets IP address <> 0.0.0.0) around half the time on the first try. I have coded this to repeatedly try until it connects. This code, executing the function EstabilshNetwork the SECOND time if it did not connect the first time will fail on the line ethernet_ENC28.Interface.Open giving the error
DHCP=True, but no connection 0.0.0.0
#### Exception System.Exception - 0x00000000 (5) ####
#### Message: NetworkEventFlags: This should never happen!
#### GHI.Premium.Net.NetworkChangeExtension::OnNetworkChangeCallback [IP: 0067] ####
#### GHI.Premium.Net.NetworkChangeExtension+NetworkChangeExtensionListener::OnEvent [IP: 000d] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
A first chance exception of type ‘System.Exception’ occurred in GHI.Premium.Net.dll

This is similar to what was reported here: https://www.ghielectronics.com/community/forum/topic?id=14802&page=1#msg149755
but I did not see a resolution…

Suggestions are appreciated.


Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Imports Gadgeteer.Modules.Seeed
Imports Microsoft.SPOT.Hardware
Imports GHI.Hardware.G400
Imports System
Imports System.Net
Imports System.Collections
Imports Microsoft.SPOT
Imports GHI.Premium.Net
Imports GHI.Premium.Net.EthernetENC28J60
Imports System.Text
Imports System.Threading
Imports Microsoft.SPOT.Net.NetworkInformation
Imports System.Net.Sockets
Imports GHI.Premium.Hardware.LowLevel


Namespace GadgeteerApp1
    Partial Public Class Program

        Private Shared server As Socket

        Dim WithEvents InternetTimer As GT.Timer = New GT.Timer(100)

        Private Shared useDHCP As Boolean = True
        Private useWebPage As Boolean = False

        '        Private Shared baro As PTmonitor

        Public Sub ProgramStarted()

            Debug.Print("Program Started")
            'baro = New PTmonitor(barometer, 0)

            char_Display.PrintString("Starting Network")

            While EstablishNetwork() = False
                char_Display.SetCursor(1, 0)
                char_Display.PrintString("...failed")
            End While
            char_Display.SetCursor(1, 0)
            char_Display.PrintString("IP:" & ethernet_ENC28.Interface.NetworkInterface.IPAddress.ToString)
            InternetTimer.Start()
        End Sub

        Private Function EstablishNetwork() As Boolean
            If ethernet_ENC28.Interface.IsOpen Then
                ethernet_ENC28.Interface.Close()
            End If
            ethernet_ENC28.Interface.Open()
            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28.Interface)
            With ethernet_ENC28.Interface
                Debug.Print("Cable connected = " & .IsCableConnected.ToString)
                Debug.Print("activated = " & .IsActivated.ToString)
                If useDHCP Then
                    Debug.Print(MacAddress)
                    .NetworkInterface.EnableDhcp()
                    .NetworkInterface.RenewDhcpLease() ' no clue if this is needed, or if this hurts
                Else
                    .NetworkInterface.EnableStaticIP("192.168.250.234", "255.255.255.0", "192.168.250.1")
                End If

            End With

            If ethernet_ENC28.Interface.NetworkInterface.IPAddress = "0.0.0.0" Then
                Debug.Print("DHCP=" & ethernet_ENC28.Interface.NetworkInterface.IsDhcpEnabled.ToString & ", but no connection " & ethernet_ENC28.Interface.NetworkInterface.IPAddress.ToString)
                Return False
            End If


            Debug.Print(ethernet_ENC28.Interface.IsOpen.ToString)
            Return True

        End Function

Assembly: GTM.GHIElectronics.Display_HD44780 (4.2.102.0) Attaching deployed file.
Assembly: RaptorNetServer (1.0.0.0) Attaching deployed file.
Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.Ethernet_ENC28 (4.2.102.0) Attaching deployed file.
Assembly: Microsoft.VisualBasic (1.0.0.0) Attaching deployed file.
Assembly: System (4.2.0.0) Attaching deployed file.
Assembly: GHI.Premium.IO (4.2.11.1) Attaching deployed file.
Assembly: GTM.GHIElectronics.UsbClientDP (4.2.102.0) Attaching deployed file.
Assembly: GHI.Premium.Net (4.2.11.1) Attaching deployed file.
Assembly: GHIElectronics.Gadgeteer.FEZRaptor (4.2.102.0) Attaching deployed file.
Assembly: Gadgeteer.SPI (2.42.0.0) Attaching deployed file.
Assembly: GHI.Hardware.G400 (4.2.11.1) Attaching deployed file.
Assembly: GTM.Seeed.Barometer (1.6.0.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.
Assembly: GHI.Premium.Hardware (4.2.11.1) Attaching deployed file.
Assembly: GHI.Premium.System (4.2.11.1) Resolving.


#2

I think some one already reported this. Seach the forum for “ows me a beer” or similar.


#3

@ Reinhard - Yes, I had noted that but as I mentioned I did not see a resolution. I was also hoping for a beer ???
A workaround would be appreciated if one exists…


#4

The problem I had was with opening a previously closed interface as that caused it to choke and spew the message in question. What I was trying to do was a pseudo reset of the network interface.


#5

@ Duke Nuken: Thanks for the reply — how did you solve the problem??? Around half the time I connect using DHCP, and half the time I do not…


#6

@ rockybooth,

I am not sure if .Close() actually performs the Dispose as it is usually the case.

Try .Dispose() right after the .Close().

I noticed that you are using .NET Gatgeteer, I hope the .Dispose() method doesn’t exist in there as it does for the plain GHI Premium NETMF.

Check my comments in the related link you mentioned: https://www.ghielectronics.com/community/forum/topic?id=14802&page=1#msg152340

Cheers!