[G400D]Ethernet Build in while debugging with visual studio

Hi everyone

I start a new topic on an already discussed but unsolved issue.

I am using a G400D based custom board with the following code:


using System;
using System.Threading;
using Microsoft.SPOT;


namespace testETH
{
    public class Program
    {
       public static void Main()
        {
            try
            {
                Thread.Sleep(5000); 
                Thread ethernetThread = new Thread(EthernetThread);
                ethernetThread.Start();

                Thread.Sleep(-1);               
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
            }
        }

        private static void EthernetThread()
        {
            DateTime now = DateTime.Now;

            using (GHI.Networking.EthernetBuiltIn ethernet = new GHI.Networking.EthernetBuiltIn())
            {
                Debug.Print("Ethernet constructor time (ms) = " + ((DateTime.Now - now).Ticks / TimeSpan.TicksPerMillisecond));

                ethernet.Open();

                ethernet.EnableStaticIP("192.168.0.133", "255.255.255.0", "0.0.0.0");

                Thread.Sleep(13000); //accept pings for this time

               // ethernet.Close();
            }
        }
    }
}


When I launch the program using visual studio, I can’t ping the board whereas when the debugger is not running all is ok.
@ John can you test this ? last time you did the test the issue didn’t occur to you and we really need to solve that as soon as possible.

@ leforban - Unfortunately we still weren’t able to reproduce whether or not VS was attached. We were able to ping fine within the 13 seconds your code provides. The only thing I can suggest is to increase the sleep time, let it sit for 10 minutes and see if a ping ever gets through, and try to test in an isolated environment with your PC and the device connected to the same router with nothing else connected, not even the WAN port.

The only way to make it works is to check the contructor duration:

This is also the case for other users. It only works when the constructor time is about 2.3s

long constructorTime = 0;
                if (eth == null)
                {
                    while (constructorTime == 0)
                    {
                        DateTime now = DateTime.Now;

                        eth = new EthernetBuiltIn();
                        constructorTime = ((DateTime.Now - now).Ticks / TimeSpan.TicksPerMillisecond);
                        Thread.Sleep(100);
                        Debug.Print("Wait...");
                        if (constructorTime==0)
                        {
                            eth.Dispose();
                        }
                        Debug.Print("Ethernet constructor time (ms) = " + constructorTime);
                    }
                }

@ leforban -

What version are you using, please?

Version of what? G400D and last official SDK (2016R1: 4.3.8.1).

what happens if you try something like the following:


            eth.NetworkInterface.PhysicalAddress = macAddress;
            if (!eth.NetworkInterface.IsDhcpEnabled)
            {
                eth.NetworkInterface.EnableDhcp();
                eth.NetworkInterface.EnableDynamicDns();
            }
            eth.UseThisNetworkInterface();

this is the code I use to initialise my G120…

I realise that it is not a static IP, but may help to see if it is the cause… also I always had problems when I didn’t call “UseThisNetworkInterface”

1 Like