ProductionUiCordonel: - serial port dispose

This commit is contained in:
Thomas Wiedebusch
2025-05-12 16:03:42 +02:00
parent 6055f4aca2
commit 8a3ab91b03
4 changed files with 23 additions and 14 deletions
@@ -419,6 +419,9 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts
/// The IrDA sniffer showed these on the communication line, but they are incompletely received.
/// Assuming the DiscardInBuffer may be delayed, so the incoming data will be scrapped.
/// </remarks>
/// <remarks date="2025-Mai-12" author="T.Wiedebusch">
/// - Dispose procedure changed.
/// </remarks>
private void ReadingThreadLoop()
{
//put the receive thread to JoinWaitSleep to avoid reading and logger output for timeout on
@@ -608,20 +611,23 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts
}
finally
{
if (_serialPort.IsOpen)
{
_serialPort.Close();
if (_serialPort.IsOpen)
{
_byteDataLogger.Info($"{Ident} Port close delay!");
Thread.Sleep(50);
_serialPort.Close();
}
_serialPort.Dispose();
_byteDataLogger.Info($"{Ident} Port is closed");
//if (_serialPort.IsOpen)
//{
// _serialPort.Close();
// if (_serialPort.IsOpen)
// {
// _byteDataLogger.Info($"{Ident} Port closing delay!");
// Thread.Sleep(500);
// _serialPort.Close();
// }
// //_serialPort.Dispose();
// //_byteDataLogger.Info($"{Ident} Port is closed");
//}
_serialPort.DiscardInBuffer();
_serialPort.DiscardOutBuffer();
_serialPort.Close();
}
_byteDataLogger.Info($"{Ident} Port is closed");
}
}