For the benefit of others.
I am using 2 serial ports running at 9600baud.
On occasion and mostly when I stopped and restarted the serial port I would get either at assert or BUFFER OVERFLW message on the LCD. This would mainly happen when I woke from a hibernate state and as such didn’t have the debugger running.
Here is an extract of my code
int bytesToRead = SerialHandle.BytesToRead;
byte[] b = new byte[bytesToRead];
SerialHandle.Read(b, 0, b.Length);
tmp = new string(UTF8Encoding.UTF8.GetChars(b));
Eventually I tracked it down to a synchronization error in the received data bytes. The serial stream I am receiving is exclusively ASCII(7 bit) coded strings. So in theory the first bit should always be ‘0’. If this is not the case the UTF8 decoder tries to decode the character as a longer unicode char and causes an error when UTF8 tries to reach beyond the end of my array to decode a multi-byte char.
My current solution as suggested here(C# console to NetDuino help? - Visual Studio - Netduino Forums) is to replace UTF8 with a custom decoder. This will still generate garbage, but that is generally ignored by my parsing code.
//New ASCII conversion to replace UTF8
tmp = new string( Bytes2Chars(b));
/// <summary>
/// Converts a byte array to a char array
/// </summary>
/// <param name="Input">The byte array</param>
/// <returns>The char array</returns>
public static char[] Bytes2Chars(byte[] Input)
{
char[] Output = new char[Input.Length];
for (int Counter = 0; Counter < Input.Length; ++Counter)
Output[Counter] = (char)Input[Counter];
return Output;
}
Unfortunately this is much slower than the native UTF8 method.
[EDIT] Running on the G120 module.