G400D - Built In Ethernet Locks Up Board

@ Andy.NApex -

Only one difference between you and me is there is no LCD screen on my ChipworkX
:think:

Maybe ship us the whole setup? Maybe even include the switch!

@ Gus -
That sounds like a good next step. Can you send me the information on where and to whom to ship it to.

@ Dat -

Something I just thought of that I didn’t make explicitly clear in my description, when you are running your test the IP address the device is trying to connect to, in my sample code would be 10.0.26.1, does that IP address exist on the network?
In other words they way I get my setup to fail is that my PC does have the IP Address 10.0.26.1 but it does not have anything listening or accepting a connection on the Port 14220.

The reason I’m asking is if i set it up so that the ip address the device is trying to connect to doesn’t exist on the network it so far has not failed.

@ Andy.NApex -

Oh, I thought try to connect to any address and when connection fails, that bug will be happened. But now it looks like different. I will check later.

To my attention to the address on the contact us page please, under company in the menu. Please include the switch you are using if you can.

@ Dat -

Have you had a chance to test when the IP Address exists on the network?

I was able to run the G400D all weekend if the IP Address does not exist on the network, but when it does exist on the network and does not accept the connection the G400D will lock up after a while.

What doe you mean by it does not exist? Network should never have the same IP on more than one device so I am not sure what you mean.

I mean the IP Address the G400 is trying to connect to does not exist on the network, not the G400’s IP Address.

@ andre.m -

I’m fully aware of that issue, if you read the previous posts it shows that I am already using a wrapper class.

Yes, I did and I am having a trouble if the IP address exists in local network. It is different with you but I think they are related together. I still don’t add it as a new know issue because I tested and saw it, still don’t know why it is yet. When everything is clear, I will go back.

Sorry because the confirmation is so late.

Hi,
Please use this for fixed version which I will send to you!

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
 using Microsoft.SPOT.Hardware;
using GHI.Premium.Net;

namespace G400_TestEthenetbuildInLookup
{
   public class Program
   {
 
      static EthernetBuiltIn eNet = new EthernetBuiltIn();
       // G400
      static OutputPort led2 = new OutputPort((Cpu.Pin)(1 * 32 + 18), true); // pb18
      static OutputPort led1 = new OutputPort((Cpu.Pin)(3 * 32 + 0), true); // pd0
      static InputPort ldr1 = new InputPort((Cpu.Pin)4, false, Port.ResistorMode.PullUp);
      static InputPort butsellect_chipworkx = new InputPort((Cpu.Pin)20, false, Port.ResistorMode.PullUp);

       //EMX
      //static OutputPort led2 = new OutputPort((Cpu.Pin)(47), true); // pb18
     // static OutputPort led1 = new OutputPort((Cpu.Pin)(47), true); // pd0
      //static InputPort ldr1 = new InputPort((Cpu.Pin)30, false, Port.ResistorMode.PullUp);
      //static InputPort butsellect_chipworkx = new InputPort((Cpu.Pin)20, false, Port.ResistorMode.PullUp);


      static int ConnectTryCount = 0;
       public static void myThreadLed()
       {
           while (true)
           {
               led1.Write(true);
               Thread.Sleep(50);
               led1.Write(false);
               Thread.Sleep(50);
           }
       }
      public static void Main()
      {
          while (ldr1.Read() == true && butsellect_chipworkx.Read() == true)
          {
              //Thread.Sleep(100);
              Debug.Print("Wait for pressing LDR1 button");
              led1.Write(true);
              Thread.Sleep(200);
              led1.Write(false);
              Thread.Sleep(200);

          }

         eNet.Open();


         //eNet.NetworkInterface.EnableStaticIP("x.x.x.x", "x.x.x.0", "x.x.x.x");
         //eNet.NetworkInterface.EnableStaticDns(new string[] { "x.x.x.x", "x.x.x.x" });
         if (eNet.NetworkInterface.IsDhcpEnabled == false)
         {
             eNet.NetworkInterface.EnableDhcp();
         }
         eNet.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(eNet_NetworkAddressChanged);
          
         NetworkInterfaceExtension.AssignNetworkingStackTo(eNet);
         int count = 0;
         while (/*eNet.NetworkInterface.IPAddress.CompareTo("0.0.0.0") == 0*/ isready== false)
          {
              Thread.Sleep(100);
              Debug.Print("Waiting for config..." + (count++) + "is Cable connected " + eNet.IsCableConnected);
          }
         //Debug.Print("IP Address: " + eNet.NetworkInterface.IPAddress);
         //Debug.Print("Subnet Mask: " + eNet.NetworkInterface.SubnetMask);
         //Debug.Print("Gateway: " + eNet.NetworkInterface.GatewayAddress);
 
         IPAddress RemoteIPAdrs = IPAddress.Parse("x.x.x.x");
         //IPAddress RemoteIPAdrs = IPAddress.Parse("10.10.1.10");
         IPEndPoint mRemoteEndPoint = new IPEndPoint(RemoteIPAdrs, 14220);
         bool IsConnected = false;
         Thread mythreadled = new Thread(myThreadLed);
         mythreadled.Start();
   
         do
         {
             Debug.Print("Socket available: " + MySocket.SocketAvailable);
            MySocket mySock = new MySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            mySock.TimeOutConnection =10 * 1000;
            ConnectTryCount++;
            Debug.Print("Connect Try #: " + ConnectTryCount.ToString() + " - " + Microsoft.SPOT.Hardware.PowerState.Uptime.ToString());
            if (mySock.Connect(mRemoteEndPoint))
            {
               IsConnected = true; //mSocket = mySock.GetSocket;
            }
            else
            {
               mySock = null;
               IsConnected = false;
            }
            mySock = null;
            //Thread.Sleep(100);
            led2.Write(ConnectTryCount%2==0);
         } while (!IsConnected);
 
 
         System.Threading.Thread.Sleep(-1);
      }
      static bool isready = false;
      static void eNet_NetworkAddressChanged(object sender, EventArgs e)
      {
          isready = false;
          Debug.Print("Event IP Address: " + eNet.NetworkInterface.IPAddress);
          Debug.Print("Event Subnet Mask: " + eNet.NetworkInterface.SubnetMask);
          Debug.Print("Event Gateway: " + eNet.NetworkInterface.GatewayAddress);
          if (eNet.NetworkInterface.IPAddress.CompareTo("0.0.0.0") != 0)
          {
              isready = true;
          }
      }
 
   }
 
   public class MySocket
   {
      static Socket[] socket;
      
      private int socket_id = 0;
      private Thread myThread;
      private EndPoint remoteEP;
      private Boolean isSocketConnected = false;
      private int connectTimeOut = 15000; // 15 second

      const int MAX_SOCKET = 40;
      const int NOT_AVAILABLE = -1;
      static int avalable_socket = MAX_SOCKET;
      static UInt64 flag = 0;

      public MySocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
      {
        int i;
        if (socket == null)
        {
            socket = new Socket[MAX_SOCKET];
        }
        if (avalable_socket == 0)
        {
            throw new Exception("avalable_socket = " + avalable_socket); 
        }
        for (i=0; i < MAX_SOCKET; i++)
        {
            UInt64 tmp = (UInt64)(1 << i);
            if ((flag & tmp) == 0)
            {
                socket_id = i;
                socket[socket_id] = new Socket(addressFamily, socketType, protocolType);
                Debug.Print("socket created: " + socket_id);
                avalable_socket--;
                flag |= tmp;
                break;
            }
        }
      }
      public void Dispose()
      {
          if (socket != null)
          {
              if (socket_id != NOT_AVAILABLE)
              {
                  socket[socket_id].Close();
                  socket[socket_id] = null;
                  avalable_socket++;

                  UInt64 tmp = (UInt64)(1 << socket_id);
                  flag &= ~tmp;
                  socket_id = NOT_AVAILABLE;

              }
          }
         
      }
      ~MySocket()
      {

          this.Dispose();
         
          
      }
      public int TimeOutConnection
      {
         get { return connectTimeOut; }
         set { connectTimeOut = value; }
      }
      static public int SocketAvailable
      {
          get { return avalable_socket; }
      }
      public Socket GetSocket
      {
         get 
         {
             if (socket_id != NOT_AVAILABLE)
             {
                 if (socket[socket_id] != null)
                     return socket[socket_id];
                     
             }
             return null; 
         }
      }
      private void CancelRequestConnect()
      {
         if (myThread != null)
         {
            try
            {
               if (myThread.IsAlive || myThread.ThreadState == ThreadState.Running)
               {
                  try
                  {

                     //myThread.Suspend();
                      if (socket != null && socket_id != NOT_AVAILABLE && socket[socket_id] != null)
                      {
                          this.Dispose();
                      }
                     myThread.Abort();
                    
                  }
                  catch
                  {
                      Debug.Print("Exception when kill a thread");
                  }
               }
               myThread = null;
               //if (socket != null && socket_id != NOT_AVAILABLE && socket[socket_id] != null)
               //{
               //    this.Dispose();
               //}
            }
            catch
            {
            }
         }
        
      }
      public Boolean Connect(EndPoint ep)
      {
         CancelRequestConnect();
         remoteEP = ep;
         isSocketConnected = false;
         myThread = new Thread(Connect);        
         myThread.Start();
         int timeout = connectTimeOut;
         while (timeout > 0)
         {
            Thread.Sleep(10);
            timeout -= 10;
            if (isSocketConnected == true)
               break;
 
         }
         if (timeout == 0) // expired
         {
            CancelRequestConnect();
         }
 
         return isSocketConnected;
      }
      private void Connect()
      {
         try
         {
             if (socket!=null && socket_id != NOT_AVAILABLE && socket[socket_id] != null)
             {
                 socket[socket_id].Connect(remoteEP);                 
             }
            isSocketConnected = true;
         }
         catch (Exception ex)
         { 
            Debug.Print("Connect Exception: " + Microsoft.SPOT.Hardware.PowerState.Uptime.ToString());
         }
      }
 
 
   }
 
}

@ Dat -

When I try to run the fixed version from the previous post I get an exception:

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Hardware.G400.dll’
#### Exception GHI.Premium.Net.NetworkInterfaceExtensionException - 0x00000000 (2) ####
#### Message:
#### GHI.Premium.Net.EthernetBuiltIn::.ctor [IP: 0011] ####
#### G400_TestEthernetBuiltInLockup_New.Program_New::.cctor [IP: 0003] ####
A first chance exception of type ‘GHI.Premium.Net.NetworkInterfaceExtensionException’ occurred in GHI.Premium.Net.dll
An unhandled exception of type ‘GHI.Premium.Net.NetworkInterfaceExtensionException’ occurred in GHI.Premium.Net.dll

@ Andy.NApex -

Something is wrong in your code. Try to remove G400.dll, we don’t need that dll. This issue is not related to firmware which I sent you.

Make sure:

  • The premium library installed on your PC is 4.2.11.1
  • The firmware is running on g400 is 9.2.11.2

If everything is correct, try to put the older firmware 4.2.11.1 to see what is going on.

Please test 9.2.11.2 and skip 9.2.11.1

I just uninstalled and installed a fresh Premium library 4.2.11.1, and g400 is running 9.2.11.2 that I sent you.

No problem found with Premium.Net.dll

@ Dat -

It must of been something on my end, not sure what exactly, but it is currently running the updated test code you have sent. It has been running now for about 1 hour and 20 minutes.

@ Andy.NApex -
is g400 Etheenet still working?