0
Answer

Serial Port Problem

Reuven Sabi

Reuven Sabi

16y
7.8k
1
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