Used device is a Domino in combination with a WIZNET Ethernet shield v.1.1 by Seeed.
The idea is to open a TCP connection and let the connection open as long the Domino is powered on. On an exception the network should be reinitialized and the connection should be opened again, just like the first time.
With the code below the connection is not recovering from an exception.
Debug info is below the code.
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
using GHIElectronics.NETMF.Net.Sockets;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System;
using System.Threading;
// References
// FEZDomino_GHIElectronics.NETMF.FEZ
// GHIElectronics.NETMF.W5100
// Microsoft.SPOT.Hardware
// Microsoft.SPOT.Native
// mscorlib
namespace NetworkTest
{
public class Program
{
static bool _firstInit = true;
static Socket _socket;
public static void Main()
{
Debug.EnableGCMessages(true);
while (true)
{
try
{
Init();
Connect();
while (true)
{
// Do some tasks and keep port open.
Thread.Sleep(5000);
Debug.Print("Throwing exception");
throw new Exception("My exception");
}
}
catch (Exception ex)
{
Debug.Print(ex.Message) ;
Debug.Print("Trying again in 5 seconds");
Thread.Sleep(5000);
}
finally
{
Disconnect();
}
}
}
public static void Init()
{
if (_firstInit)
{
FirstInit();
_firstInit = false;
}
else
{
ReInit();
}
}
public static void FirstInit()
{
byte[] mac = { 40, 0, 0, 0, 254, 237 };
byte[] ip = { 192, 168, 253, 213 }; // Static IP address of the ethernet shield
byte[] subnet = { 255, 255, 255, 0 }; // Subment Mask
byte[] gateway = { 192, 168, 253, 1 }; // Gateway IP address
byte[] dns = { 192, 168, 253, 1 }; // DNS server address
// Connect using Static IP address
Debug.Print("FirstInit: Enabling");
WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, true); // WIZnet interface on FEZ Panda
NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
NetworkInterface.EnableStaticDns(dns);
Debug.Print("FirstInit: Enabled");
}
public static void ReInit()
{
Debug.Print("ReInit: ReInitializing");
WIZnet_W5100.ReintializeNetworking();
Debug.Print("ReInit: ReInitialized");
}
protected static void Connect()
{
string remoteIP = "192.168.253.91";
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(remoteIP), 12000);
Debug.Print("Connect: Connecting to " + remoteEndPoint.ToString());
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Tcp);
_socket.Connect(remoteEndPoint);
Debug.Print("Connect: Connected");
}
protected static void Disconnect()
{
Debug.Print("Disconnect: Closing");
_socket.Close();
_socket = null;
Debug.Print("Disconnect: Closed");
}
}
}
Debug output:
FirstInit: Enabling
FirstInit: Enabled
Connect: Connecting to 192.168.253.91:12000
Connect: Connected
Throwing exception
#### Exception System.Exception - 0x00000000 (1) ####
#### Message: My exception
#### NetworkTest.Program::Main [IP: 002b] ####
A first chance exception of type 'System.Exception' occurred in NetworkTest.exe
My exception
Trying again in 5 seconds
Disconnect: Closing
Disconnect: Closed
ReInit: ReInitializing
ReInit: ReInitialized
Connect: Connecting to 192.168.253.91:12000
#### Exception System.Exception - 0x00000000 (1) ####
#### Message: Timeout occurs during connection establishment
#### GHIElectronics.NETMF.Net.SocketNative::connect [IP: 0135] ####
#### GHIElectronics.NETMF.Net.Sockets.Socket::Connect [IP: 002c] ####
#### NetworkTest.Program::Connect [IP: 0030] ####
#### NetworkTest.Program::Main [IP: 0011] ####
A first chance exception of type 'System.Exception' occurred in GHIElectronics.NETMF.W5100.dll
Timeout occurs during connection establishment
Trying again in 5 seconds
Disconnect: Closing
Disconnect: Closed
ReInit: ReInitializing
ReInit: ReInitialized
Connect: Connecting to 192.168.253.91:12000
#### Exception System.Exception - 0x00000000 (1) ####
#### Message: Timeout occurs during connection establishment
#### GHIElectronics.NETMF.Net.SocketNative::connect [IP: 0135] ####
#### GHIElectronics.NETMF.Net.Sockets.Socket::Connect [IP: 002c] ####
#### NetworkTest.Program::Connect [IP: 0030] ####
#### NetworkTest.Program::Main [IP: 0011] ####
A first chance exception of type 'System.Exception' occurred in GHIElectronics.NETMF.W5100.dll
Timeout occurs during connection establishment
Trying again in 5 seconds
....
And it will continue looping.
What does the WIZnet_W5100.ReintializeNetworking() command exactly do? Does it result in a short flash of the RST LED on the network board?
I’ve read on older models of the network board pin9 and the reset pin should be connected.