var netif = new EthernetBuiltIn();
netif.Open();
var hasNetwork = netif.NetworkIsAvailable;
var hasCable = netif.CableConnected;
netif.EnableDhcp();
netif.EnableDynamicDns();
It looks like it’s never even detecting that the cable is plugged in - the network activity LEDs never light up and hasCable is always false.
When it hits EnableDhcp() it throws this exception:
_ethernet = new EthernetBuiltIn();
_ethernet.EnableDhcp();
_ethernet.EnableDynamicDns();
_ethernet.Open();
while (_ethernet.IPAddress == "0.0.0.0")
{
var hasNetwork = _ethernet.NetworkIsAvailable;
var hasCable = _ethernet.CableConnected;
Debug.Print("Waiting for DHCP");
Thread.Sleep(250);
}
Interestingly, when I do that it does [em]not[/em] throw an exception. But it still does not detect that the cable is plugged in. The while() loop runs forever.
I have also tried setting the addresses statically:
{"8.8.8.8", "192.168.1.1"};
const string staticIp = "192.168.1.177";
const string netMask = "255.255.255.0";
const string gatewayIp = "192.168.1.1";
try
{
_ethernet = new EthernetBuiltIn();
//_ethernet.EnableDhcp();
//_ethernet.EnableDynamicDns();
_ethernet.EnableStaticIP(staticIp, netMask, gatewayIp);
_ethernet.EnableStaticDns(dnsAddresses);
_ethernet.Open();
while (_ethernet.IPAddress == "0.0.0.0")
{
var hasNetwork = _ethernet.NetworkIsAvailable;
var hasCable = _ethernet.CableConnected;
Debug.Print("Waiting for DHCP");
Thread.Sleep(250);
}
...
and, if non-gadgeteer, you should add these code before open the interface:
NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
var eth = new EthernetENC28J60(SPI.SPI_module.SPI1,
GHI.Pins.Generic.GetPin('A', 13),
GHI.Pins.Generic.GetPin('A', 14),
GHI.Pins.Generic.GetPin('B', 10));
eth.EnableDhcp();
eth.EnableDynamicDns();
eth.Open();
while (eth.IPAddress == "0.0.0.0")
{
Debug.Print("Waiting for DHCP");
Thread.Sleep(250);
}
I tried the above code and the loop never exits. The activity lights never turn on. I have tried multiple cables and several different Ethernet switches.
I also tried this with the same effect:
var eth = Mainboard.Ethernet;
...
Any ideas on how to troubleshoot/debug this further?
[quote=“Mike”]Did you see the comment from John?
[/quote]
Yes, and it looked like he included the specific pins for my board in his response. I tried those pin assignments and got the same results. If there is other documentation on the pins for my specific board I have yet to find it.
[quote=“Lurch”]I use a somewhat different sequence and it works…
[/quote]
Actually it looks like the pin assignments in your code is identica to minel. A13 / A14 / B10.
@ Brett - I have tried several “known good” cables, connected to my switch and directly to my router. None of the Ethernet lights have lit up at any point.
Hmmmm …
In desperation, I tried connecting the cable directly to my laptop. This time both activity lights did indeed come on. I will try setting a static IP address and see if I can actually talk to it.
Apparently some of the digital I/O pins conflict with the Ethernet controller. After I moved the connections I had on those pins everything appears to be working.