Hello,
The topic with similar issue was already submitted (http://www.ghielectronics.com/community/forum/topic?id=8557) however the solution not supplied.
We have multiple Hydra devices (~20) using for HW and FW testing purposes. The devices run with Ethernet FW.
The network configured on device initializing stage.
Our users experienced with problem that after number of resets / power re-connects Hydra device stopping to response with “USB device not recognized” message and yellow bang in Device Manager.
The recovery can be done using FW update only.
I tried to investigate the problem with very simple code (below) running on Hydra and client that checks that Hydra is alive over network. If Hydra is alive the clients restarts it using MFDeploy tool.
I found that after ~ 10-15 restarts the problem reproduced and Hydra FW indeed crashes.
The code compiled and deployed in Release mode with USB serial device used for debugging messages connect to Hydra socket 6.
Hydra code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using Gadgeteer.Interfaces;
using Microsoft.SPOT;
using Microsoft.SPOT.Net.NetworkInformation;
namespace HydraTest
{
/// <summary>
/// Main entry point for the execution program
/// </summary>
public partial class Program
{
#region Private members
private bool _initialized;
private NetworkInterface _networkInterface;
private System.Net.Sockets.Socket _server;
#endregion
#region Control events and init
// This method is run when the mainboard is powered up or reset.
private void ProgramStarted()
{
lED7R.TurnLightOn(1);
lED7R.TurnLightOn(2);
if (usbSerial1 != null)
{
usbSerial1.Configure(38400, Serial.SerialParity.None, Serial.SerialStopBits.One, 8);
usbSerial1.SerialLine.Open();
}
Start();
}
private void Start()
{
if (_initialized)
return;
DebugPrint("Entering to initialize network");
Thread.Sleep(500);
InitializeNetwork();
_initialized = true;
Thread.Sleep(1000);
DebugPrint("Network initialized");
//usbSerial1.SerialLine.Write("Network initialized" + "EndMessage");
Thread.Sleep(1000);
lED7R.TurnLightOn(7);
}
#endregion
#region Network stack
private void InitializeNetwork()
{
DebugPrint("Initializing network...");
try
{
DebugPrint("Getting interfaces");
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
DebugPrint("Interfaces received");
if (interfaces != null && interfaces.Length > 0)
{
DebugPrint("Got " + interfaces.Length + " network interfaces...");
_networkInterface = interfaces[0];
DebugPrint("Try initializing network with Static configurations...");
_networkInterface.EnableStaticIP("10.12.227.200", "255.255.255.0", "10.12.227.3");
DebugPrint("Network initialized. IP Address: " + _networkInterface.IPAddress);
_server = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_server.Bind(new IPEndPoint(IPAddress.Parse(_networkInterface.IPAddress), 81));
DebugPrint("Bound...");
_server.Listen(3);
Thread.Sleep(1000);
DebugPrint("Listening...");
return;
}
DebugPrint("No network interface founded...");
}
catch (Exception )
{
DebugPrint("Error");
//e.LogMe("InitializeNetwork");
}
}
#endregion
#region Helpers
/// <summary>
/// Prints message to debug and COM
/// </summary>
/// <param name="message"></param>
public void DebugPrint(string message)
{
if (message == null || message == string.Empty)
return;
var stringBuilder = new StringBuilder();
stringBuilder.Append(message);
Debug.Print(stringBuilder.ToString());
stringBuilder.Append("EndMessage");
var bytes = Encoding.UTF8.GetBytes(stringBuilder.ToString());
if (usbSerial1 != null)
usbSerial1.SerialLine.Write(bytes, 0, bytes.Length);
}
#endregion
}
}
Client code
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace SocketHdyraClient
{
class Program
{
private const int TOTAL_TRIES = 50;
static void Main(string[] args)
{
for (int i = 0; i < 50; i++)
{
Console.WriteLine("Stressing Hydra attempt {0} from {1}",i,TOTAL_TRIES);
try
{
if (!ConnectSocket())
{
Console.WriteLine("Failed to connect");
return;
}
Console.WriteLine("Restarting Hydra");
var p = Process.Start(@ "C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Tools\MFDeploy.exe",
"Reboot /I:USB:FEZ Hydra_Gadgeteer");
p.WaitForExit();
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception:{0}",e.Message);
return;
}
Console.WriteLine("Entering sleep for 5 seconds");
for (int j = 0; j < 5; j++)
{
Console.Write(".");
Thread.Sleep(TimeSpan.FromSeconds(1));
}
}
}
private static bool ConnectSocket()
{
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var ep = new IPEndPoint(IPAddress.Parse("10.12.227.200"), 81);
var result = socket.BeginConnect(ep, null, null);
bool success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(10), true);
if (success)
{
socket.EndConnect(result);
}
else
{
socket.Close();
return false;
}
return true;
}
}
}
DeviceInfo:
HAL build info: 4.2.0.0, Microsoft Copyright (C) Microsoft Corporation. All rig
OEM Product codes (vendor, model, SKU): 255, 0, 65535
Serial Numbers (module, system):
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Solution Build Info: 4.2.5.0, Copyright (C) GHI Electronics, LLC
AppDomains:
default, id=1
Assemblies:
mscorlib,4.2.0.0
Microsoft.SPOT.Native,4.2.0.0
Microsoft.SPOT.Hardware,4.2.0.0
Microsoft.SPOT.Graphics,4.2.0.0
Microsoft.SPOT.TinyCore,4.2.0.0
Microsoft.SPOT.IO,4.2.0.0
System.IO,4.2.0.0
Microsoft.SPOT.Hardware.Usb,4.2.0.0
Microsoft.SPOT.Hardware.SerialPort,4.2.0.0
Microsoft.SPOT.Touch,4.2.0.0
Microsoft.SPOT.Ink,4.2.0.0
Microsoft.SPOT.Hardware.PWM,4.2.0.1
Microsoft.SPOT.Hardware.OneWire,4.2.0.0
System.Xml,4.2.0.0
Microsoft.SPOT.Time,4.2.0.0
Microsoft.SPOT.Net,4.2.0.0
System,4.2.0.0
Microsoft.SPOT.Net.Security,4.2.0.0
System.Net.Security,4.2.0.0
Hydra, client and COM listener projects can be mailed for debugging or reproduction purposes.