DataReceived Event handler not receiving messages using c#

Posted by karthik on Stack Overflow See other posts from Stack Overflow or by karthik
Published on 2010-04-09T01:22:37Z Indexed on 2010/04/09 1:23 UTC
Read the original article Hit count: 362

Filed under:
|

I'm using the below code to receive the messages using serial port event handler. But it dosent receives any.I am not getting errors. The code breaks in "string msg = comport.Readline()" Am i doing something wrong ?

public partial class SerialPortScanner : Form

{ private SerialPort comPort = new SerialPort();

public SerialPortScanner()
{
    InitializeComponent();
    comPort.Open();
    comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived);

}


void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    if (comPort.IsOpen == true)
    {
        string msg = comPort.ReadLine();
        MessageBox.Show(msg);
    }
}

}

© Stack Overflow or respective owner

Related posts about c#3.0

Related posts about serial-port