MagFlux: - extension

This commit is contained in:
Thomas Wiedebusch 2023-03-10 08:41:21 +01:00
parent b8f0b97a2f
commit 65ce515d4d
4 changed files with 14 additions and 10 deletions

View File

@ -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
}
}

View File

@ -31,7 +31,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.MeasurementRecor
/// </summary>
public UInt32 StatusBits;
/// <summary>
/// String delimiter to separate elements in ToString() routine
/// </summary>
private const String StringDelimiter = "; \n";
/// <summary>
/// Get result as string
/// </summary>
@ -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)

View File

@ -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);

View File

@ -7,7 +7,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol
{
/// <inheritdoc />
/// <summary>
/// Layer between <see cref="T:Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol.StreamingDecoder" /> CRC16CCITT handler and Events
/// Layer between <see cref="StreamingDecoder" /> CRC16CCITT handler and Events
/// block trashy telegrams
/// </summary>
public class StreamingProtocol : BaseProtocol