Managing Ports and Transfers in .NET
private void ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
SerialError SerialErrorReceived1;
SerialErrorReceived1 = e.EventType;
switch (SerialErrorReceived1)
{
case SerialError.Frame:
Console.WriteLine("Framing error.");
break;
case SerialError.Overrun:
Console.WriteLine("Character buffer overrun.");
break;
case SerialError.RXOver:
Console.WriteLine("Input buffer overflow.");
break;
case SerialError.RXParity:
Console.WriteLine("Parity error.");
break;
case SerialError.TXFull:
Console.WriteLine("Output buffer full.");
break;
}
}
The Frame, Overrun, and RXParity errors originate in the UART’s Line Status
register. The RXOver and TXFull errors report the status of the driver’s soft-
ware buffers.
With a well-structured application and robust hardware design, all of these
errors should be rare. Very frequent Framing and Parity errors typically indicate
port parameters that don’t match on the sending and receiving computers.
Occasional Framing or Parity errors can indicate a noisy line that requires a dif-
ferent cable or another hardware fix. Increasing ReadBufferSize can eliminate
RXOver errors. To eliminate TXFull errors, ensure that the buffer has room
before writing data to the port. Increasing WriteBufferSize can also eliminate
TXFull errors and can make the application code more efficient by enabling
writing larger blocks of data to the port.