Hi all,
I have my domino up and running, and am playing with the ethernet shield…just getting used to the api etc…
So I found the API docs, and in there is an Ethernet example where the program connects to the dns server and obtains an IP, dns address, etc…
When I run the code, I get an exception right away in the code
if (!Ethernet.IsEnabled)
I get the following error…
An unhandled exception of type 'System.NotSupportedException' occurred in dns1.exe
The cable is plugged in, the router is working etc…
Is there a setting I need to do to tell it to enable ethernet?
Here is the complete code from the example…
Thoughts?
~Kam (^8*
/// Add these libraries to your project's References
/// System
/// Microsoft.SPOT.Net
/// GHIElectronics.NETMF.System
/// GHIElectronics.NETMF.Net
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Net.NetworkInformation;
using GHIElectronics.NETMF.Net;
using System.Net;
namespace Ethernet_Example_4._0
{
public class Program
{
static public bool ethernet_event = false;
static public bool ethernet_last_status = false;
static public bool network_is_read = false;
static public ManualResetEvent NetworkAvailablityBlocking = null;
public static void Main()
{
if (!Ethernet.IsEnabled)
{
Ethernet.Enable();
}
NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
NetworkInterface[] netif = NetworkInterface.GetAllNetworkInterfaces();
// Ethernet is always the first interface netif[0]
NetworkAvailablityBlocking = new ManualResetEvent(false);
if (!Ethernet.IsCableConnected)
{
Debug.Print("Cable is not connected!");
NetworkAvailablityBlocking.Reset();
while (!NetworkAvailablityBlocking.WaitOne(5000, false))
{
if (!Ethernet.IsCableConnected)
{
Debug.Print("Cable is not connected!");
Debug.Print("Still waiting.");
}
else
break;
}
}
Debug.Print("Ethernet cable is connected!");
Debug.Print("Enable DHCP");
try
{
if (!netif[0].IsDhcpEnabled)
netif[0].EnableDhcp();// This function is blocking
else
{
netif[0].RenewDhcpLease();// This function is blocking
}
network_is_read = true;
Debug.Print("Network settings:");
Debug.Print("IP Address: " + netif[0].IPAddress);
Debug.Print("Subnet Mask: " + netif[0].SubnetMask);
Debug.Print("Default Getway: " + netif[0].GatewayAddress);
Debug.Print("DNS Server: " + netif[0].DnsAddresses[0]);
}
catch
{
Debug.Print("DHCP Faild");
}
Debug.Print("Test DNS");
try
{
IPHostEntry myIP = Dns.GetHostEntry("www.ghielectronics.com");
if (myIP != null)
{
Debug.Print(myIP.HostName + ": " + myIP.AddressList[0].ToString());
}
}
catch
{
Debug.Print("Faild to Get the host entry of the FQN from DNS server!");
}
Thread.Sleep(Timeout.Infinite);
}
static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
if (e.IsAvailable)
{
if (Ethernet.IsCableConnected)
{
if (ethernet_last_status != true)
{
ethernet_last_status = true;
NetworkAvailablityBlocking.Set();
}
}
}
else
{
if (!WiFi.IsLinkConnected)
{
if (ethernet_last_status != false)
{
ethernet_last_status = false;
network_is_read = false;
}
}
}
}
}
}