C# Serial Communications - Received Data Lost

Posted by Jim Fell on Stack Overflow See other posts from Stack Overflow or by Jim Fell
Published on 2010-05-06T15:35:49Z Indexed on 2010/05/06 15:48 UTC
Read the original article Hit count: 212

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about serial-communication