Hello all,
I am using a Cerberus running 4.2. I have an RS232 module, an ENC28 module and a Char display.
My app takes Serial data massages it and creates an XML file that I am pushing out a socket connection on the ethernet port.
It all runs fine for about a half hour then just freezes…the debug messages stop, the socket stops publishing…just dead.
I am not seeing any exceptions or threads being abandoned.
I have tried the serial port on its own thread and on the main thread. I have read that some people are giving the serial port a sleep(10) to allow for GC, but I felt like that was in a system they were writing to not reading from.
That’s definitely a memory issue. Like Gus said, try an optimize code. Also throw it into RELEASE mode instead of DEBUG, this will free up a few resources for you.
I am trying to separate the code to make it simpler, it is difficult… did notice something though.
I am making a socket connection to a Time server using with some adapted code I saw on here.
As you can see it is an extension method of DateTime.
After it runs for a while It will start to throw exceptions of “System.Net.Sockets.SocketException” error code 10055…
When it hits the New Socket(… command
once this starts to fail, it will continue to fail…looks like indefinately
Here is the code:
public static void SetFromNetwork(this DateTime dateTime, TimeSpan timeZoneOffset)
{
var ran = new Random(DateTime.Now.Millisecond);
var servers = new[]
{
"time-a.nist.gov",
"time-b.nist.gov",
"nist1-la.ustiming.org",
"nist1-chi.ustiming.org",
"nist1-ny.ustiming.org"
};
Debug.Print("Setting Date and Time from Network");
try
{
//Fails here
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
var endpoint = servers[ran.Next(servers.Length)];
Debug.Print("Calling Time server" + endpoint);
var endPoint = new IPEndPoint(Dns.GetHostEntry(endpoint).AddressList[0], 123);
socket.Connect(endPoint);
var timeServerMessage = new byte[48]; // RFC 2030
timeServerMessage[0] = 0x1B;
for (int x = 1; x < 48; x++)
{
timeServerMessage[x] = 0;
}
socket.Send(timeServerMessage);
socket.Receive(timeServerMessage);
socket.Close();
byte offsetTransmitTime = 40;
ulong intpart = 0;
ulong fractpart = 0;
for (int x = 0; x <= 3; x++)
{
intpart = 256*intpart + timeServerMessage[offsetTransmitTime + x];
}
for (int x = 4; x <= 7; x++)
{
fractpart = 256*fractpart + timeServerMessage[offsetTransmitTime + x];
}
ulong milliseconds = (intpart*1000 + (fractpart*1000)/0x100000000L);
if (timeServerMessage[47] != 0)
{
TimeSpan timeSpan = TimeSpan.FromTicks((long) milliseconds*TimeSpan.TicksPerMillisecond);
var tempDateTime = new DateTime(1900, 1, 1);
tempDateTime += timeSpan;
DateTime networkDateTime = (tempDateTime + timeZoneOffset);
Debug.Print(networkDateTime.ToString());
Utility.SetLocalTime(networkDateTime);
}
}
catch (Exception ex)
{
Debug.Print("Time sync threw and exception:" + ex.Message);
}
}
}
What does “run out of buffers” mean?
How do I fix it?
The socket is created, used, and closed.
The call is coming from a discrete thread just for sync of the clock.
I am not using a buffer.
after closing the socket set the var to null. then do a Debug.GC(true). see if that helps.
10055 means IP ran out of buffers. you might have a memory problem somewhere else in your program. when you do Debug.GC it will display available memory.