Reading Binary data from a Serial Port.

Posted by rross on Stack Overflow See other posts from Stack Overflow or by rross
Published on 2010-04-16T19:01:04Z Indexed on 2010/04/16 19:03 UTC
Read the original article Hit count: 378

Filed under:
|
|
|

I previously have been reading NMEA data from a GPS via a serial port using C#. Now I'm doing something similar, but instead of GPS from a serial. I'm attempting to read a KISS Statement from a TNC. I'm using this event handler.

comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

Here is port_DataReceived.

        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        string data = comport.ReadExisting();

        sBuffer = data;

        try
        {
            this.Invoke(new EventHandler(delegate { ProcessBuffer(sBuffer); }));
        }
        catch { }
    }

The problem I'm having is that the method is being called several times per statement. So the ProcessBuffer method is being called with only a partial statment. How can I read the whole statement?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET