From 65ce515d4d4be3eeb2e7ec11508cd1767ae7c1c7 Mon Sep 17 00:00:00 2001 From: Thomas Wiedebusch Date: Fri, 10 Mar 2023 08:41:21 +0100 Subject: [PATCH] MagFlux: - extension --- .../Interfaces/Ports/SerialPorts/BaseSerialPort.cs | 13 +++++++------ .../MeasurementRecords/MagFluxRecord.cs | 6 +++++- .../Protocols/StreamingProtocol/StreamingDecoder.cs | 3 +-- .../StreamingProtocol/StreamingProtocol.cs | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Common/Hardware/Interfaces/Ports/SerialPorts/BaseSerialPort.cs b/Common/Hardware/Interfaces/Ports/SerialPorts/BaseSerialPort.cs index 64fee313..559838d0 100644 --- a/Common/Hardware/Interfaces/Ports/SerialPorts/BaseSerialPort.cs +++ b/Common/Hardware/Interfaces/Ports/SerialPorts/BaseSerialPort.cs @@ -290,7 +290,7 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts //put the actual time stamp to this record being able to assign it correctly //even if the decoding is delayed. This time stamp will be used to do the first - //synchronization at start and stop of the measurement. Therefor the serial buffer + //synchronization at start and stop of the measurement. Therefore the serial buffer //has to be flushed in advance to avoid wrong time stamp to "old" records _receiveTimeStampPc = DateTimeOffset.UtcNow; @@ -438,7 +438,7 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts //read line of ASCII indicated by syncByte == null if (null == PortSettingsForTransmitProtocol.ProtSyncByte) { - //exit is timeout or received line + //exit is timeout from serialPort or received line var rxStringRecord = _serialPort.ReadLine(); if (!string.IsNullOrEmpty(rxStringRecord)) @@ -554,11 +554,16 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts { throw; } catch (TimeoutException) { + //ATTENTION: This "_serialPort.DiscardInBuffer()" caused a lot of trouble as it flushes a few incoming + //bytes and therefore destroys the already started data stream. Here it had been left in to indicate + //this critical issue! + /*-------------------------------DO NOT ACTIVATE-----------------------------------------------------*/ //flush receive buffer at timeout to force task to enter JoinWaitSleep state in finally //if (_serialPort.IsOpen) //{ // _serialPort.DiscardInBuffer(); //} + /*---------------------------------------------------------------------------------------------------*/ _byteDataLogger.Trace($"{Ident} Read timeout({InterByteReadDelayMs}ms)"); //_byteDataLogger.Trace($"{Ident} Read timeout({PortSettingsForTransmitProtocol.ResponseTimeoutMs}ms)"); @@ -673,7 +678,6 @@ 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(); @@ -684,8 +688,5 @@ namespace Xylem.Common.Hardware.Interfaces.Ports.SerialPorts _byteDataLogger.Error($"{Ident} {ex.Message}"); } } - - #region Prop - #endregion } } diff --git a/Common/Hardware/WaterMeter/Genesis/DataPackages/MeasurementRecords/MagFluxRecord.cs b/Common/Hardware/WaterMeter/Genesis/DataPackages/MeasurementRecords/MagFluxRecord.cs index c7fec536..3ad16c79 100644 --- a/Common/Hardware/WaterMeter/Genesis/DataPackages/MeasurementRecords/MagFluxRecord.cs +++ b/Common/Hardware/WaterMeter/Genesis/DataPackages/MeasurementRecords/MagFluxRecord.cs @@ -31,7 +31,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.MeasurementRecor /// public UInt32 StatusBits; + /// + /// String delimiter to separate elements in ToString() routine + /// private const String StringDelimiter = "; \n"; + /// /// Get result as string /// @@ -45,7 +49,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.MeasurementRecor .Append($"Status: {StatusBits:X8}").Append(StringDelimiter) .Append($"UniqueId: {UniqueId}").Append(StringDelimiter) .Append($"SensorSN: {SensorId}").Append(StringDelimiter) - .Append($"CRC: {Crc:X4}").Append(StringDelimiter) + .Append($"CRC: 0x{Crc:X4}").Append(StringDelimiter) .Append($"OverflowVolume [m³]: {OverflowVolumeCm}").Append(StringDelimiter) .Append($"OverflowTime [s]: {OverflowTimeS}").Append(StringDelimiter) .Append($"IsValid: {IsValid}").Append(StringDelimiter) diff --git a/Common/Hardware/WaterMeter/Genesis/Protocols/StreamingProtocol/StreamingDecoder.cs b/Common/Hardware/WaterMeter/Genesis/Protocols/StreamingProtocol/StreamingDecoder.cs index 30e57bfe..8bd1ec27 100644 --- a/Common/Hardware/WaterMeter/Genesis/Protocols/StreamingProtocol/StreamingDecoder.cs +++ b/Common/Hardware/WaterMeter/Genesis/Protocols/StreamingProtocol/StreamingDecoder.cs @@ -146,7 +146,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol //MagFlux test string from Jan Bennett 2023-03-09 //rawMsg = "@l 34c21 e6e56 3c40f883 0 3c005d5232500120373235 0 5790" - //DN50 //2022-07-21 07:22:06.9871 | @f 8497D 062E4216 9B2A //2022-07-21 07:22:06.9871 | @h 1 0 0A1F59C4 00017A43 00115C45 72E1596B 00000400 00001998 7D91B652 7D4F37E6 000191E6 0C 062E4A9C 5331 @@ -184,7 +183,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol byteArray[i] = (Byte)rawRecordForCrc[i]; } - var calculatedCrc = rawMsgFields[0] == "@l" ? // for MagFlux protocol "l" + var calculatedCrc = rawMsgFields[0] == "@l" ? // for MagFlux protocol "l" (small L) Crc16Ccitt.ModbusRtuLsbA001(byteArray) : Crc16Ccitt.CalculateMsb1021(byteArray); diff --git a/Common/Hardware/WaterMeter/Genesis/Protocols/StreamingProtocol/StreamingProtocol.cs b/Common/Hardware/WaterMeter/Genesis/Protocols/StreamingProtocol/StreamingProtocol.cs index 3cf8aade..c05da207 100644 --- a/Common/Hardware/WaterMeter/Genesis/Protocols/StreamingProtocol/StreamingProtocol.cs +++ b/Common/Hardware/WaterMeter/Genesis/Protocols/StreamingProtocol/StreamingProtocol.cs @@ -7,7 +7,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol { /// /// - /// Layer between CRC16CCITT handler and Events + /// Layer between CRC16CCITT handler and Events /// block trashy telegrams /// public class StreamingProtocol : BaseProtocol