How to Read Device Data From serial port

Posted by Aamir Khurshid on Stack Overflow See other posts from Stack Overflow or by Aamir Khurshid
Published on 2010-05-04T10:30:29Z Indexed on 2010/05/04 11:48 UTC
Read the original article Hit count: 262

Filed under:
|

I have one device which sends data on COM port say on COM13. Now i want to read that data and display it in the RichTextBox or in any text control.

I have written the application with the help of IO and IO.Ports but comport.DataRecived event does not fire, even though device is sending data on that port.

I have some software on which i define the port number and it successfully display data, which insure me that data is receiving on the Port but i am unable to receive.

Is there any way i can read data?

comm.Parity = cboParity.Text;//None
comm.StopBits = cboStop.Text;//One
comm.DataBits = cboData.Text;//8
comm.BaudRate = cboBaud.Text;//9600
comm.DisplayWindow = rtbDisplay;//Null
comm.PortName = "COM13";
comm.OpenPort();

cmdOpen.Enabled = false;
cmdClose.Enabled = true;
cmdSend.Enabled = true;

public bool OpenPort()
{
    if (comPort.IsOpen)
    {
        comPort.Close();
    }

    comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived);
    comPort.PortName = _portName;
    comPort.Open();return true;
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf