Add clear buffer for serialPort

This commit is contained in:
atef 2026-02-13 09:40:57 +01:00
parent bc130ea99c
commit 105a4e59f5
1 changed files with 17 additions and 1 deletions

View File

@ -37,6 +37,22 @@ public class SerialPortChannel : ConnectionChannel<SerialPort>
};
}
// 👇 NEW: this is where we actually flush the serial buffers
protected override void ClearBuffers(SerialPort serialPort)
{
try
{
serialPort.DiscardInBuffer();
serialPort.DiscardOutBuffer();
Console.WriteLine(" Buffer in and out discarded.");
}
catch
{
Console.WriteLine(" couldn't clear the Buffer .");
// ignore if port is closed / disposed
}
}
protected override SerialPort Open() => _Open();
protected override void Close(SerialPort serialPort) => serialPort.Dispose();