C# Serial Communications - Received Data Lost
- by Jim Fell
Hello. Received data in my C# application is getting lost due to the collector array being over-written, rather than appended.
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
pUartData_c = serialPort1.ReadExisting().ToCharArray();
bUartDataReady_c = true;
}
catch ( System.Exception ex )
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
In this example pUartData_c is over-written every time new data is received. On some systems this is not a problem because the data comes in quickly enough. However, on other systems data in the receive buffer is not complete. How can I append received data to pUartData_c, rather than over-write it. I am using Microsoft Visual C# 2008 Express Edition. Thanks.