Hi !
I have tested to receive 3 byte of serial data to a FEZ Domino in an Event and that eats up my memory, and it ends with program crash.
GC: 3msec 28104 bytes used, 36276 bytes available
GC: 3msec 33348 bytes used, 31032 bytes available
GC: 3msec 37392 bytes used, 26988 bytes available
GC: 3msec 37224 bytes used, 27156 bytes available
GC: 3msec 39552 bytes used, 24828 bytes available
GC: 3msec 48240 bytes used, 16140 bytes available
GC: 3msec 61548 bytes used, 2832 bytes available
Failed allocation for 17 blocks, 204 bytes
I have come to the conclusion that when i use serialPort.Read(RX_buffer, 0, 3); it reduce the memory, but when i use serialPort.BytetoRead i got 1 char at time and memory is not reducing.
Here is a code sample that i use
I have also seen that if i use different Thread.sleep times in the end of the main do…while loop
it changes the time it takes to eat up memory, the fates way is to use Timout.Infinite
Any one who have a clue ??
using System;
using System.Threading;
using System.IO;
using System.Text;
using System.IO.Ports;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.IO;
namespace FezDominoTest1
{
public class Program
{
public static SerialPort serialPort;
static OutputPort LED;
static byte[] RX_buffer = new byte[50];
static void RunMyTimer(object o)
{
Debug.Print("Timer evnt");
LED.Write(!LED.Read());
}
static void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int count = serialPort.Read(RX_buffer, 0, 3);
char[] chars = Encoding.UTF8.GetChars(RX_buffer);
string str = new string(chars, 0, count);
Debug.Print(str);
// RX_buffer = null;
}
public static void Main()
{
serialPort = new SerialPort("COM2", 9600, Parity.None);
serialPort.Open();
serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);
Timer MyTimer = new Timer(new TimerCallback(RunMyTimer), null, 0, 5000);
//do
//{
Thread.Sleep(Timeout.Infinite);
//}
//while (true);
}
}
}