Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerialPort.ParityReplace not working on Linux #110349

Open
floribe2000 opened this issue Dec 3, 2024 · 1 comment
Open

SerialPort.ParityReplace not working on Linux #110349

floribe2000 opened this issue Dec 3, 2024 · 1 comment
Labels
area-System.IO.Ports untriaged New issue has not been triaged by the area owner

Comments

@floribe2000
Copy link

Description

System.IO.Ports.SerialPort has a property "ParityReplace" which, according to docs, controls how bytes with parity errors are replaced. The docs also state that settings this value to "0" disables replacement and simply accepts even invalid bytes.
This behaviour is important when dealing with low-level serial communication where parity bits are sometimes used as signal bits to wake up devices.

On Linux, this property has no effect since it is not implemented in the source code, which does not match the documentation.

Reproduction Steps

var port = new SerialPort("/dev/ttyX", 9600, Parity.Space, 8, StopBits.One);
port.ParityReplace = 0;
port.Open();
while (true)
{
  Console.WriteLine(port.ReadByte());
}

A serial device using Parity.Mark behaviour for indicating the begin of new messages is required to test this.

Expected behavior

Assuming the same input on windows and linux, the same output is expected.

Actual behavior

On Windows, it works as expected, on Linux, all start bits (with the parity bit set to 1) are considered as invalid and are not shown.

Regression?

No response

Known Workarounds

No response

Configuration

  • NET 9.0
  • Windows 11 (x64), Debian Bookworm (arm64) (both with latest patches)

Other information

The problem is caused by the ParityReplace property being ignored in the linux source code.
To implement the correct behaviour (or at least the partial correct behaviour which would allow to ignore parity errors) it may be sufficient to add a new parameter to the native methods that sets the IGNPAR flag on the termios struct and set that based on the value of ParityReplace.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 3, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io-ports
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO.Ports untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

1 participant