It is a documentation bug. The actual replacement character is '?', ASCII code 63.
Missing "126" on parity error
-
29-03-2022 - |
Frage
I have a COM port that I know receive invalid parity bits and I'm using the following program, however I never seem to get the trailing 126
byte that the documentation mentions.
In the following program the console prints lots of !!!!!
but no ?????
, why?
Also I'm assuming that the byte with the invalid parity bit will still be included in the stream?
using (var serialPort = new SerialPort())
{
serialPort.PortName = "COM2";
serialPort.BaudRate = 562500;
serialPort.Parity = Parity.Space;
serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One;
serialPort.ErrorReceived += (s, e) => Console.WriteLine("!!!!!");
serialPort.Open();
var thread = new Thread(() =>
{
while (isRunning)
{
var b = serialPort.ReadByte();
if (b == 126)
Console.WriteLine("?????");
}
});
thread.Start();
Console.WriteLine("");
Console.WriteLine("Press any key to exit.");
Console.ReadKey(true);
isRunning = false;
thread.Join();
}
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow