0
Reply

Serial Port Problem

Reuven Sabi

Reuven Sabi

Aug 7 2008 9:58 AM
7.8k
I am  getting Exceptions while trying to Connect/Reconnect  from the port using Microsoft Dot Net 2.0 Serial Port Component.

The Following Settings are used:

1.Parity-None

2.Stop Bits-One

3.Baud Rate-9600

4.Handshake-None


When i said Connect/Reconnect  I literally mean connect and Disconnect serial port (plug in and plug out).

I am getting the System.IO.Ports.SerialErrorReceivedEventArgs exception

with following properties

     base: {System.IO.Ports.SerialErrorReceivedEventArgs}
     EventType : Frame


Code Example:


SerialPort serialPort = new SerialPort();
serialPort.ErrorReceived += HabndleError;
serialPort.DataReceived += HandleDataReceived;

serialPort.PortName = "COM1"
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.DataBits = 8;
serialPort.BaudRate = 9600;

serialPort.Open();


private void HandleDataReceived(object sender, SerialDataReceivedEventArgs e)
{
    //Do Something
}

private void HabndleError(object sender, SerialErrorReceivedEventArgs e)
{
            MessageBox.Show(e.ToString());
}


Thanks in advance