Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.35k stars 287 forks source link

Detect parity errors #236

Closed ghost closed 5 years ago

ghost commented 5 years ago

Is there a way to detect parity errors? For instance, if the parity bit should be set given the settings and you receive data that does not have the bit set, what happens?

hedgecrw commented 5 years ago

In this library, there is not currently a way to detect parity errors. The way that each OS handles parity errors (and for that matter, each configuration within each OS) is completely different...some discard them, some prepend them, some ignore them, some log them somewhere separate, and some crash...so in an effort to keep this library simple and not bloated, we don't include parity error detection. If a parity error is detected, the corresponding bytes are simply discarded.

The best way to handle this in your application code would to use some sort of framing and/or transmission of the expected packet length. Aside from doing this, there really isn't any other way to reliable and generically report a parity error given the way the library is currently set up.