Well, interesting…
Before you posted, I had changed the code that did not work, to use Di9. It then wouldn’t reset the W5100! So I changed it back to Di7, and indeed it does reset the device. But then I wonder why the example code works with Di9?
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using GHIElectronics.NETMF.Net.NetworkInformation;
using System.Text;
using Socket = GHIElectronics.NETMF.Net.Sockets.Socket;
public class Program
{
public static void Main()
{
byte[] ip = { 192, 168, 1, 100 };
byte[] subnet = { 255, 255, 255, 0 };
byte[] gateway = { 192, 168, 1, 254 };
byte[] mac = { 0x00, 0x26, 0x1C, 0x7B, 0x29,0xE8 };
// Enable the WIZnet_5100 chipset, on the specified pins
WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, true);
// Enable the program to set and use a static IP address
NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
// Not sure why we need this when we are specifying a static IP address...
NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 1, 254 });
// Create a socket
Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
// Specify the destination endpoint
IPAddress DestinationIP = new IPAddress(new byte[] { 192, 168, 1, 254 });
IPEndPoint DestinationEndPoint = new IPEndPoint(DestinationIP, 2000);
// Create a string to pass to the PC, then serialize it to a byte array
String msg = "Hello PC";
byte[] byteArrayOutputBuffer = Encoding.UTF8.GetBytes(msg);
while (true)
{
// Send the byte array to the PC via the socket
mySocket.SendTo(byteArrayOutputBuffer, byteArrayOutputBuffer.Length, SocketFlags.None, DestinationEndPoint);
//while (mySocket.Poll(2000000, SelectMode.SelectRead))
//{
// If the amount of data available on the socket is greater than 0
if (mySocket.Available > 0)
{
// Create a byte array to receive incoming UDP data
byte[] byteArrayInputBuffer = new byte[mySocket.Available];
// Define a network endpoint
//EndPoint recEndPoint = new IPEndPoint(IPAddress.Any, 0);
EndPoint recEndPoint = new IPEndPoint(IPAddress.Any, 2000);
// Read incoming UDP data from the specified endpoint into the input buffer array
mySocket.ReceiveFrom(byteArrayInputBuffer, ref recEndPoint);
// If the data isn't being sent on the same port as we're listening, disgard it
if (!recEndPoint.Equals(DestinationEndPoint))// Check if the received packet is from the 192.168.0.2
continue;
// Output the received data to the debug console
Debug.Print(new String(Encoding.UTF8.GetChars(byteArrayInputBuffer)));
}
//}
}
}
}
Note that I’ve commented out the inner “while” loop, because I am not really sure what it’s doing, and the example code certainly works without it. I didn’t post my UDPServer code, but it’s basically right out of the example in the “Internet of Things” text. So I am perplexed still, on this Di7 vs Di9 thing–but it’s clear that Di7 at least causes my W5100 to reset.
Thanks for your post.
TB
EDIT: Just had a thought… Maybe Di9 is used for reset on the other ethernet controller chips, besides the W5100?