At this stage of development, the NetWorkUp event of GHI Electronics Ethernet_J11D module does not work with the latest .NET Gadgeteer SDK. The reasons are explained in the forum thread here: http://www.tinyclr.com/forum/21/5010/ The fix is not public yet.
GHI has good documentation, so I adapted code from their example in the topic: Ethernet Class. So far, the ethernet class I created only supports my application using the Seeed Pulse Oximeter sensor. The single method of my class sends data from the Seeed Pulse Oximeter to a Web service. I’ll post this complete scenario eventually, but you can piece it together from a couple of other posts:
Seeed Pulse Oximeter .NET Gadgeteer Module
REST Web Service to Record Data from a .NET Gadgeteer Sensor Device
To use the EthernetConnection class, create an instance and call the single method as in the following ButtonPressed event handler.
EthernetConnection connection = new EthernetConnection(); void button_ButtonPressed(Button sender, Button.ButtonState state) { Debug.Print("Sending data"); bool success = connection.SendPulseOximeterData("TestName3", "65", "98"); }
The EthernetConnection class is shown in the following code block.
class EthernetConnection { static public ManualResetEvent NetworkAvailablityBlocking = null; NetworkInterface[] netif = NetworkInterface.GetAllNetworkInterfaces(); static public bool network_is_read = false; public EthernetConnection() { if (!GHINET.Ethernet.IsEnabled) { GHINET.Ethernet.Enable(); } if (!GHINET.Ethernet.IsCableConnected) { Debug.Print("Cable is not connected!"); NetworkAvailablityBlocking.Reset(); while (!NetworkAvailablityBlocking.WaitOne(5000, false)) { if (!GHINET.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"); } } public bool SendPulseOximeterData(string name, string pulse, string oxg) { bool success = false; using (HttpWebRequest request = WebRequest.Create("http://integral-data.com/PulseOxgData/reading/" + name + "/" + pulse + "/" + oxg) as HttpWebRequest) { request.Method = "POST"; request.ContentLength = 0; HttpWebResponse response; try { response = request.GetResponse() as HttpWebResponse; if(response.StatusCode == HttpStatusCode.OK) success = true; response.Close(); } catch (Exception ex) { string exception = ex.Message + " Inner:" + ex.InnerException; Debug.Print(exception); Debug.Print(exception); } } return success; } }
#1 by Marco Minerva on December 9, 2011 - 4:31 AM
Great post!
I have tried Ethernet_J11D Module with two different DHCP servers, but I have encountered no problems. So, I think I was lucky 🙂 Thank you for sharing your solution!
I hope the new version of .NET Gadgeteer SDK will be released soon!
#2 by Michael Dodaro on December 9, 2011 - 7:54 AM
The version of the GHIElectronics .NET Gadgeteer SDK that I installed is a test version: http://tinyclr.com/forum/12/4891/. A new version to be released soon has repaired the problem with the Ethernet_J11D module.
#3 by G. Andrew Duthie on December 12, 2011 - 1:02 PM
I think it would be more accurate to say that some of the events don’t work with the 1.1 version of the Ethernet_J11D module driver. Oddly, it was working in an earlier version, so hopefully it’ll be fixed soon.
But the networking itself works fine…was just testing it using UDP sockets, and data flows quite nicely (too nicely, in fact…have to figure out how to throttle it on the client side, as I’m getting too much too fast…good problem to have, I suppose).
#4 by Michael Dodaro on December 12, 2011 - 2:04 PM
G. Andrew,
Have you been able to make the Ethernet_J11D work as a .NET Gadgeteer module in an application using the Hydra test version of the SDK?
I noticed the NetworkUp and NetworkDown events were out, but I tried to send GET and POST requests, and they failed. The only way I found to work around was to leave out the .NET Gadgeteer object and run from NETMF.
#5 by G. Andrew Duthie on December 12, 2011 - 3:38 PM
Michael,
Have not yet tried the Ethernet_J11D with the FEZ Hydra mainboard. I’m using the FEZ Spider in my current project, and it works fine. I have installed the Hydra version of the SDK, but I’m not sure whether that would make any difference, since AFAIK, the driver files are the same.
As noted above, I have an earlier version of the same project that uses older versions of the drivers and it does fire the NetworkUp event, and both projects are able to send and receive data fine.
Such are the perils of working with beta software and hardware. 🙂