Main Site Documentation

Strange Networking Issue


#1

We were having an issue with one of our EMX Module devices out on site were it was experiencing networking issues and not responding to pings. Swapped it out with a spare and brought it back to diagnose, and here’s the weird bit:

When I debug the device through visual studio the device responds to pings no problem. But when it is running just standalone no response to pings.

To reduce any chance of a coding problem, I removed out the onsite application and deployed a very simple application that basically just starts up and configures the Ethernet.

So, does anybody have any ideas what is so special about debugging in visual studiok?


#2

Can you show the code?


#3

Sure, though the code should be the same running in debug as when running in standalone.



        //______________
        // ethernet
        private static EthernetBuiltIn Ethernet;

        public static void Main()
        {
            InitialiseNetworkInterface();

            while (true)
            {
                Thread.Sleep(500);
            }
        }
        private static void InitialiseNetworkInterface()
        {
            try
            {
                //_______________
                // open ethernet
                Ethernet = new EthernetBuiltIn();
                Ethernet.Open();

                //___________________________
                // set activity event raised
                Ethernet.CableConnectivityChanged += new EthernetBuiltIn.CableConnectivityChangedEventHandler(Ethernet_CableConnectivityChanged);
                Ethernet.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Ethernet_NetworkAddressChanged);

                //________
                // assign
                NetworkInterfaceExtension.AssignNetworkingStackTo(Ethernet);

                //___________________
                // configure network
                ConfigureNetworkInterface();

                //_________________________
                // check network interface
                if (!Ethernet.IsActivated)
                {
                    Debug.Print("No active network interfaces.");
                }
            }
            catch (Exception ex)
            {
                Debug.Print("InitialiseNetworkInterface(): " + ex.Message);
            }
        }

        private static void Ethernet_CableConnectivityChanged(object sender, EthernetBuiltIn.CableConnectivityEventArgs e)
        {
            try
            {
                Debug.Print("Built-in Ethernet Cable is " + (e.IsConnected ? "Connected!" : "Disconnected!"));
            }
            catch { }
        }

        private static void Ethernet_NetworkAddressChanged(object sender, EventArgs e)
        {
            try
            {
                Debug.Print("New address for The built-in Ethernet Network Interface");
                Debug.Print("Is DhCp enabled: " + Ethernet.NetworkInterface.IsDhcpEnabled);
                Debug.Print("Is DynamicDnsEnabled enabled: " + Ethernet.NetworkInterface.IsDynamicDnsEnabled);
                Debug.Print("NetworkInterfaceType " + Ethernet.NetworkInterface.NetworkInterfaceType);
                Debug.Print("Network settings:");
                Debug.Print("IP Address: " + Ethernet.NetworkInterface.IPAddress);
                Debug.Print("Subnet Mask: " + Ethernet.NetworkInterface.SubnetMask);
                Debug.Print("Default Getway: " + Ethernet.NetworkInterface.GatewayAddress);
                Debug.Print("Number of DNS servers:" + Ethernet.NetworkInterface.DnsAddresses.Length);
            }
            catch { }
        }

        private static void ConfigureNetworkInterface()
        {
            try
            {
                Debug.Print("Configuring network interface.");
                Ethernet.NetworkInterface.EnableStaticIP("10.10.10.254", "255.255.0.0", "10.1.0.1");
            }
            catch (Exception ex)
            {
                Debug.Print("InitialiseNetworkInterface(): " + ex.Message);
            }
        }



#4

Code runs slower under the debugger.

The only thing that I can think of is some weird hard to reproduce timing issue which can be code or hardware related.

Sorry, not much help here.


#5

Maybe when debugging, the program gives time to the several process to initiate properly the PHY and interface, but not when running fast mode…

You should add some stuffs that will test on several steps (Cable connection, interface assignment, and so on).

Sample can be found here :

https://www.ghielectronics.com/community/codeshare/entry/588

Let us know…


#6

@ Chris_MC -

I copy exactly your code, juts modify IP addess and it works fine for me.

Try to connect-reconnect cable, or debug by click Connect on MFDeploy to see what is going on your board.


#7

Try debugging to a display if you have one or use an LED if you don’t to know where it gets stuck…


#8

@ Chris_MC - Did you try to reflash the firmware?


#9

Hi andre.m how can i check the watchdog.
I mean is there is any way to hang the Microcontroller…?


#10

I want to test the Watchdog practically. Is there is any possibilities to Hang the micro controller through programming, something like run lot of threads, use maximum memory, doing big calculations.

Am using the register class and manage the watchdog, it resets when the counter not reloaded,
Am try hang the controller through the above steps without success.

If any possibilities… ?


#11

Divide by zero at some point :smiley:


#12

I don’t know what you mean, can you clarify it…?
sorry for for the late reply, am in my weekend.


#13

I mean divide a value by 0 in you code and it will crash your application. If watchdog is set up it will restart your application.


#14

Hi Architect,
Am try like this


 int a = 20;
 int b = 0;
 int c = a /b;

But it always throw System.Exception…

Edit:
And also am try


 int a = 0;
 int b = 0;
 int c = a /b;

Its also throw System.Exception…
Any idea…?


#15

@ YuvaRaja -

System.Exception when dividing by 0 is normal. The idea now is to exit the Main() when this error occur :


...
Main(...)
{
try
   {
      Debug.Print("Starting....");
      int a = 20;
      int b = 0:

      int c = a/b;
   }
catch () 
{
      Debug.Print("Crashing....");    <= Catch but do nothing, then it will exit main...
 }  
} 


#16

same trouble with my cerbuino!
solved?


#17

Don’t know if it was solved,

but something I did was to implement a retry pattern during IP configuration as I noticed that sometimes it did more than once to initiate correctly…

This code works fine for me so you can try it !


        public static void Initialize(bool useDHCP, string ipAddress, string subNetMask, string gateway, string dnsServer1, string dnsServer2)
        {
            try
            {
                if (m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.Initializing);

                Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI2, GHI.Hardware.G120.Pin.P1_17, GHI.Hardware.G120.Pin.P0_5, GHI.Hardware.G120.Pin.P1_14);
                Eth1.CableConnectivityChanged += new EthernetENC28J60.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
                Eth1.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);
                Eth1.Open();

                if (!Eth1.IsOpen)
                {
                    if(m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.HardwarePHYProblem);
                    throw new Exception();
                }                    
                if(m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.HardwarePHYOK);

                bool _succeed = false;
                int _retry = 0;
                do
                {
                    try
                    {
                        NetworkInterfaceExtension.AssignNetworkingStackTo(Eth1);
                        _succeed = true;
                        if(m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.InterfaceAssignationOK);
                        break;
                    }
                    catch
                    {
                        _succeed = false;
                        _retry++;
                        if(m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.InterfaceAssignationProblem);
                    }
                }
                while (_retry < 100);
                if (!_succeed) throw new Exception();

                NetworkAvailabilityBlocking = new ManualResetEvent(false);
                _retry = 0;
                do
                {
                    if (Eth1.IsCableConnected)
                    {
                        if (m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.ConnectedCable);
                        break;
                    }
                    else
                    {
                        if (m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.DisconnectedCable);
                        _retry++;
                    }
                }
                while (!NetworkAvailabilityBlocking.WaitOne(500, false) & _retry < 100);
                if (!Eth1.IsCableConnected) throw new Exception();

                try
                {
                    if (useDHCP)
                    {
                        Thread.Sleep(1);
                        NetworkInterfaceExtension.AssignedNetworkInterface.NetworkInterface.EnableDhcp();
                    }
                    else
                    {
                        // Assign
                        Thread.Sleep(1);
                        NetworkInterfaceExtension.AssignedNetworkInterface.NetworkInterface.EnableStaticIP(ipAddress, subNetMask, gateway);

                        // DNS
                        int _dnsserverlength = 0;
                        if (dnsServer1.Trim().Length > 0) _dnsserverlength++;
                        if (dnsServer2.Trim().Length > 0) _dnsserverlength++;
                        if (_dnsserverlength > 0)
                        {
                            string[] _dnss = new string[_dnsserverlength];
                            if (dnsServer1.Trim().Length > 0) _dnss[0] = dnsServer1;
                            if (dnsServer2.Trim().Length > 0) _dnss[1] = dnsServer2;
                            //
                            NetworkInterfaceExtension.AssignedNetworkInterface.NetworkInterface.EnableStaticDns(_dnss);
                        }
                    }
                    if (m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.IPConfigurationOK);
                }
                catch 
                {
                    if (m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.IPConfigurationProblem);
                    throw new Exception();
                }

                if (m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.Online);
            }
            catch
            {
                if (m_OnEthernetConnectionStatusChanged != null) m_OnEthernetConnectionStatusChanged(IPManagerStatus.Aborted);
            }
        }


#18

Hello Louis Do you know on average how many attempts are needed to have it working?

I am also experiencing some issues using the EthernetBuiltIn of the EMX. IsCable Conneected returns true avec even if it is disconnected. I see on wireshark that IP is given to the EMX but can’t ping in some cases without knowing why. Restarting the computer sometimes work, sometimes not…


#19

Hi,

Been awhile since I updated on this problem. I have spent a lot of time investigating and some things have moved on from the original post.

The original connection with debugging in visual studio was slightly misleading. The device in question uses POE and it seems the first time it is powered on, with the cable being inserted, that the original problem with no apparent network or ability to ping appears. If the device initiates a soft reset (which debugging in Visual Studio effectively also does) then the network and pinging is fine - so it was not in fact debugging that fixed the device, but a soft reset.

This leads me to think that the issue is related to the plugging in of the cable, which provides both power and the network, and that something isn’t being activated/initialized properly during that powering-on stage. This points towards more of a hardware issue, or at the very least a software level below that of the NETMF Framework that I work at. I work mainly on the software side, so don’t really know how much control or influence the EMX module has over our Ethernet Module.

One thing to note is that the status information coming from the EthernetBuiltIn object is all good i.e. cable is connected, it is activated, and it is open.


#20

Hello Chris
In fact after verification, the cable connected information is also good… I still do not know why yesterday i observed some troubles about this.

I 'll try to check if I had the same behavior than you on my design