Main Site Documentation

FEZHydra networking and R2-Beta2 release


#1

I’m testing some code ported to 4.3 to FEZHydra. I starting to check ethernet code and doesn.t work.



        static EthernetENC28J60 CreateEthernetInterface()
        {
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                Debug.Print(" -> " + nic.NetworkInterfaceType.ToString());
            }

            // ********** FEZHydra ****
            //Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI1, GHI.Pins.Generic.GetPin('A', 29),
            //                                    GHI.Pins.Generic.GetPin('D', 17), GHI.Pins.Generic.GetPin('A', 13), 4000);
            //Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI1, GHI.Pins.G400.PB13, 
            //                                 GHI.Pins.G400.PB8   , GHI.Pins.G400.PB9, 4000);
            Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI1, (Cpu.Pin) 45, (Cpu.Pin) 40, (Cpu.Pin) 41, 4000); //socket 3
            //Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI1, (Cpu.Pin) 46, (Cpu.Pin) 34, (Cpu.Pin) 11, 4000); // socket 4

            return Eth1;
        }


        static void StartEthernet()
        {
            Eth1 = CreateEthernetInterface();
            NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);
            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(Eth1_CableConnectivityChanged);
            Eth1.Open();

            Eth1.NetworkInterface.EnableStaticIP(_boardIp, _boardNetmask, _boardGw); // class C net
            string [] DnsAddresses = new string[] { "8.8.8.8" , "192.168.20.1"};
            Eth1.NetworkInterface.EnableStaticDns(DnsAddresses);
            Eth1.NetworkInterface.PhysicalAddress = new byte[] { 0x00, 0xC0, 0x03, 0x00, 0xC1, 0x05 }; // MACADDR: 00-C0-03-00-C1-03
            if (!Eth1.CableConnected)
            {
                NetworkAvailablityBlocking = new ManualResetEvent(false);
                do
                {
                    if (!Eth1.CableConnected)
                    {
                        Debug.Print("Ethernet cable is not connected yet.");
                    }
                    else
                        break;
                }
                while (!NetworkAvailablityBlocking.WaitOne(5000, false));
            }           
            while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any)
            {
                Debug.Print("IP address is not set yet.");
            }
            Debug.Print("IP address is set " + Eth1.NetworkInterface.IPAddress.ToString() + " - " + EthernetENC28J60.ActiveInterface.IPAddress);
        }

        static void Eth1_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("New address for The built-in Ethernet Network Interface ");

            Debug.Print("Is DhCp enabled: " + Eth1.NetworkInterface.IsDhcpEnabled);
            Debug.Print("Is DynamicDnsEnabled enabled: " + Eth1.NetworkInterface.IsDynamicDnsEnabled);
            Debug.Print("NetworkInterfaceType " + Eth1.NetworkInterface.NetworkInterfaceType);
            Debug.Print("Network settings:");
            Debug.Print("IP Address: " + Eth1.NetworkInterface.IPAddress);
            Debug.Print("Subnet Mask: " + Eth1.NetworkInterface.SubnetMask);
            Debug.Print("Default Getway: " + Eth1.NetworkInterface.GatewayAddress);
            Debug.Print("Number of DNS servers:" + Eth1.NetworkInterface.DnsAddresses.Length);

            for (int i = 0; i < Eth1.NetworkInterface.DnsAddresses.Length; i++)
                Debug.Print("DNS Server " + i.ToString() + ":" + Eth1.NetworkInterface.DnsAddresses[i]);

            Debug.Print("----------------------------------------------");
        }


The ENC28 module is created runtime and not via gadgeteer GUI and is plugged on socket 3 (S) (but same result on socket 4).
The board is not pingable but arp is resolved to correct mac addr.
I’ve no clue. Did I forget something for 4.3 eth initialization ?


#2

Hi,

I had the same problem in the beta release. The network was definitely not running on hydra. I tried DHCP and fix IP…


#3

I was able to reproduce the issue. As a temporary workaround, if I commented out setting the PhysicalAddress, everything worked properly.


#4

Hi John,

I tried this setup from a 4.2 project working on the hydra.

I was nor able to get a connect to my router with or without DHCP…

       void SetupLAN(bool DHCPEnable, string IP, string Subnet, string Gateway, string DNSServer)
        {
            Debug.Print("\r\n+++ SetupLAN +++");
            //LAN
            Debug.Print("Initializing network...");
            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            if (interfaces != null && interfaces.Length > 0)
            {
                NetworkInterface networkInterface = interfaces[0];
                Boolean isDhcpWorked = false;
                // dynamic IP address
                if (networkInterface.IsDhcpEnabled == false) networkInterface.EnableDhcp();
                // Wait for DHCP (on LWIP devices)

                if (DHCPEnable == true)
                {
                    for (int i = 0; i < 5; i++)
                    {

                        networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
                        if (networkInterface.IPAddress != "0.0.0.0")
                        {
                            isDhcpWorked = true;
                            break;
                        }

                        Debug.Print("Waiting for an IP Address...");
                        Thread.Sleep(1000);
                    }
                }

                if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU != 3)
                {
                    if (isDhcpWorked == false)
                    {
                        //static IP address
                        networkInterface.EnableStaticIP(IP, Subnet, Gateway);
                        networkInterface.EnableStaticDns(new[] { DNSServer });
                        //string h = "df";
                        Debug.Print("DHCP not enabled");
                    }
                }

                Debug.Print("Network is ready");
                Debug.Print("  IP Address: " + networkInterface.IPAddress);
                Debug.Print("  Subnet Mask: " + networkInterface.SubnetMask);
                Debug.Print("  Default Getway: " + networkInterface.GatewayAddress);
                Debug.Print("  DNS Server: " + networkInterface.DnsAddresses[0]);
            }
            else
            {
                Debug.Print("No network device found");
            }

        }

#5

@ MiRo - Is that for 4.2 or 4.3 in the beta SDK?


#6

Hi John,

I tried this code in a 4.3 SDK beta release copied from a working 4.2 Project.


#7

Uhh funny solution ! I will try…


#8

I’ve done some tests and the workaround works, but the Hydra board resets itself after net startup every +o- 10 sec. I saw other thread on this problem.
MFDeploy and FEZ Config can’t setup manually the network.
Definitely not usable network with SDK 4.3 for Hydra.

EDIT: I got the problem inside my code now and it’s working if get rid of the MAC setting line.
But still can cofigure network in the FEZConfig (can’t read/write settings) and in MFDeploy (it can read, but not apply settings)


#9

@ dobova -

Make sure you used latest version of FEZ Config. The older from 4.2 does not work on 4.3.
And try again if the tool says “No responds from device”


#10

@ Dat - I’m using last FEZConfig from SDK Beta2 (v 2.0.1.0). It can’t get/set parameters from Hydra under “Network Configuration”. I’ve tested on various OS with same results: can’t read/write (“No response from device”). I can read parameter using MFDeploy 4.3.1 but then I can’t write them to board.
For more info: I can deploy/debug/clr-ping the board without any issue. I’ve same problem with LCD Configuration (can’t read/write parameter settings under “LCD Configuration”).
I’ve testes 2 different Hydra with same results.


#11

I found that still exists in Beta2 SDK the problem on SD IO, when ReadLine() is called on a line with no char and a CR before:


 #### Exception System.IndexOutOfRangeException - 0xa9000000 (13) ####
    #### Message: 
    #### System.IO.StreamReader::Peek [IP: 001c] ####
    #### System.IO.StreamReader::ReadLine [IP: 005e] ####


#12

@ dobova -

You can set PhysicalAddress before calling Open().


#13

@ Dat - thank you for the suggestion!


#14

@ MiRo - Hydra networking changed in 4.3. You have to use GHI.Networking.ENC28 now just like you do on the Premium boards.


#15

I’ve ported the same code used for hydra on the G400HDR (fw 4.3.1).
Lot of issues:

  • USB problems when debugging and deploying code. Several time need more than 3-4 reset to attach the debugger. Often the debugger locks after deploy and before program run.
  • Network Enc28 works worse than Hydra. The board is pingable and I can run timeservice (my class not netmf class), socket lockup randomly but often.
  • No network code (socket and httplistener at least) works when running board without usb attached to the debugger. I will debug via serial port to understand more about this issue. (Debug.Print problems ?)
  • SD card works, but ReadLine() crashes if empty line is present after CR/LF.
  • I2C run fine … lol