BaseSerialPort:

- Flush buffer (DiscardInBuffer) removed as some bytes are missing from time to time.  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.

IrdaTransmitProtocol:
- WakeUpMessage marked and debug output
This commit is contained in:
Thomas Wiedebusch
2022-07-15 17:18:12 +02:00
parent 2f87d186a0
commit bac97f8e57
7 changed files with 49 additions and 16 deletions
@@ -409,6 +409,11 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts
/// <remarks date="2019-Dec-14" author="T.Wiedebusch">
/// - Flush buffer if received length is 0.
/// </remarks>
/// <remarks date="2022-Jul-15" author="T.Wiedebusch">
/// - Flush buffer (DiscardInBuffer) removed as some bytes are missing from time to time.
/// 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>
private void ReadingThreadLoop()
{
//put the receive thread to JoinWaitSleep to avoid reading and logger output for timeout on
@@ -464,7 +469,7 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts
rxByte = (Byte)_serialPort.ReadByte();
//record raw data stream for output on missing sync-byte to investigate this issue
rxRawRecord.Add(rxByte);
} while ((_serialPort.BytesToRead > 0) && (PortSettingsForTransmitProtocol.ProtSyncByte != rxByte));
} while (_serialPort.BytesToRead > 0 && PortSettingsForTransmitProtocol.ProtSyncByte != rxByte);
// if syncByte has not been detected skip read loop and wait for next incoming record
if (PortSettingsForTransmitProtocol.ProtSyncByte == rxByte)
@@ -545,10 +550,10 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts
catch (TimeoutException)
{
//flush receive buffer at timeout to force task to enter JoinWaitSleep state in finally
if (_serialPort.IsOpen)
{
_serialPort.DiscardInBuffer();
}
//if (_serialPort.IsOpen)
//{
// _serialPort.DiscardInBuffer();
//}
_byteDataLogger.Trace($"{Ident} Read timeout({InterByteReadDelayMs}ms)");
//_byteDataLogger.Trace($"{Ident} Read timeout({PortSettingsForTransmitProtocol.ResponseTimeoutMs}ms)");
@@ -655,6 +660,7 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts
_serialPort.Write(txByteList.ToArray(), 0, txByteList.Count);
//TODO THW flush before sending NOT after
// flush the buffer for MOXA, to avoid two subsequent communications assembled to one communication!
_serialPort.BaseStream.Flush();