0

.NET SerialPort class has Parity property. But this class doesn't contains methods to detect parity errors. Is there some way to check parity errors and handle it? Or this checking and fixing is at the hardware level and developer shouldn't worry about this?

Aave
  • 548
  • 1
  • 5
  • 15
  • *"Or this checking and fixing ..."* -- Parity has no error correction capability.. It also can't detect two-bits errors. Typically parity errors are not reported to userspace by the device driver. Relying on parity for detection of transmission errors is typically a waste of effort/time. Use a CRC. – sawdust May 13 '20 at 08:32
  • @sawdust it's clear. But is there way to get parity errors via .NET? – Aave May 13 '20 at 08:58

1 Answers1

1

In the specification, by registering Delegate in SerialErrorReceivedEventHandler, SerialPort.ErrorReceived Event can be received and processed.

The error that occurred is notified to SerialErrorReceivedEventArgs.EventType Property.

The value is represented by SerialError Enum.

Fields

Frame    8  The hardware detected a framing error.  
Overrun  2  A character-buffer overrun has occurred. The next character is lost.  
RXOver   1  An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.  
RXParity 4  The hardware detected a parity error.  
TXFull 256  The application tried to transmit a character, but the output buffer was full.  

However, please be aware that you may not always be notified at strict timing.
Just because it's written in the spec doesn't mean it's really implemented as you expected.

Community
  • 1
  • 1
kunif
  • 4,060
  • 2
  • 10
  • 30