FM2014: - prepared for multiple FM2014s - 6.Step

This commit is contained in:
Thomas Wiedebusch 2026-01-31 18:28:26 +01:00
parent c167b22102
commit fd837cd947
6 changed files with 57 additions and 50 deletions

View File

@ -642,15 +642,15 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Co
/// Get the command type like addressing to individual with and without answer or broadcast
/// </summary>
/// <param name="cmdName"></param>
/// <returns>command type</returns>
/// <returns>Command type</returns>
/// <remarks date="2026-Jan-10" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static CmdType GetCmdCmdType(CmdName cmdName)
public static CmdType GetCmdType(CmdName cmdName)
{
return (from ct in CmdTbl
where ct.CmdName == cmdName
select ct.CmdType).FirstOrDefault();
where ct.CmdName == cmdName
select ct.CmdType).FirstOrDefault();
}
}
}

View File

@ -453,12 +453,12 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
// Check for individual command without response
if (CmdType.INDIVIDUAL_UNRESPONSIVE == SharedCmdTypeReminderLastCmd &&
CmdType.INDIVIDUAL_UNRESPONSIVE == GetCmdCmdType(cmdName))
CmdType.INDIVIDUAL_UNRESPONSIVE == GetCmdType(cmdName))
{
statusReturn = StatusReturn.Skipped;
}
else if (CmdType.INDIVIDUAL == SharedCmdTypeReminderLastCmd &&
CmdType.INDIVIDUAL == GetCmdCmdType(cmdName))
CmdType.INDIVIDUAL == GetCmdType(cmdName))
{
// Read or timeout with a TimeoutException
var answerStr = SharedSerialPort?.ReadTo(END_OF_STR);
@ -515,7 +515,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
// Initiate communication using the individual or broadcast address
var retVal = true;
if (CmdType.BROADCAST == GetCmdCmdType(cmdName))
if (CmdType.BROADCAST == GetCmdType(cmdName))
{
if (SharedCmdTypeReminderLastCmd != CmdType.BROADCAST)
{
@ -546,7 +546,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
if (dataObj == null)
{
SharedSerialPort.Write($"{cmdCodeStr}{END_OF_STR}");
var additionalInfo = GetCmdCmdType(cmdName) == CmdType.BROADCAST
var additionalInfo = GetCmdType(cmdName) == CmdType.BROADCAST
? Resources.StrCommDirectionSetup
: Resources.StrCommDirectionRequest;
response = new CmdResponse(cmdName, $"{additionalInfo}: {info}");
@ -698,7 +698,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
fm2014.ConnectResponse = fm2014.ConnectResponse.Replace(ADDR_RECORD_STR, "");
var fields = fm2014.ConnectResponse.Split('.');
fm2014.FwVersion = fields[1];
SharedCmdTypeReminderLastCmd = GetCmdCmdType(cmdName);
SharedCmdTypeReminderLastCmd = GetCmdType(cmdName);
return true;
}
}
@ -756,6 +756,9 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// <remarks date="2026-Jan-28..29" author="Thomas Wiedebusch">
/// - Support for multiple FM2014s.
/// </remarks>
/// <remarks date="2026-Jan-31" author="Thomas Wiedebusch">
/// - If any FM2014 has REF and DUT pulse counter on then use for ALL the synchronized readout.
/// </remarks>
public Boolean PulseCounterMeasurement(Boolean refCtrOn = true, Boolean dutCtrOn = false)
{
if (!IsLoggedOn || (!refCtrOn && !dutCtrOn))
@ -820,35 +823,38 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
do
{
foreach (var fm2014 in RegisteredFm2014s.Where(fm2014 => fm2014.IsLoggedOn))
CmdName cmdNameRef;
CmdName cmdNameDut;
Boolean syncPulseCtr;
// Check if any FM2014 has a synchronized request to synchronize all FM2014 pulse counter values
if (RegisteredFm2014s.Any(x => x.RefPulseCtrOn && x.DutPulseCtrOn))
{
try
cmdNameDut = CmdName.CMD_DUT_GET_PLS_CTR_BU;
cmdNameRef = CmdName.CMD_REF_GET_PLS_CTR_BU;
syncPulseCtr = true;
}
else
{
cmdNameDut = CmdName.CMD_DUT_GET_PLS_CTR;
cmdNameRef = CmdName.CMD_REF_GET_PLS_CTR;
syncPulseCtr = false;
}
// Get the process information
var infoRef = GetCmdInfo(cmdNameRef);
var infoDut = GetCmdInfo(cmdNameDut);
try
{
// Make a backup of the pulse counters to synchronize those and read out the backups
if (SharedCyclicMeasSequ != CyclicMeasSequ.IDLE && syncPulseCtr)
{
CmdName cmdNameRef;
CmdName cmdNameDut;
// Select the actual or backup pulse counter value command
if (fm2014.DutPulseCtrOn && fm2014.RefPulseCtrOn)
{
cmdNameDut = CmdName.CMD_DUT_GET_PLS_CTR_BU;
cmdNameRef = CmdName.CMD_REF_GET_PLS_CTR_BU;
}
else
{
cmdNameDut = CmdName.CMD_DUT_GET_PLS_CTR;
cmdNameRef = CmdName.CMD_REF_GET_PLS_CTR;
}
// Get the process information
var infoRef = GetCmdInfo(cmdNameRef);
var infoDut = GetCmdInfo(cmdNameDut);
// Make a backup of the pulse counters to synchronize those and read out the backups
if (SharedCyclicMeasSequ != CyclicMeasSequ.IDLE &&
fm2014.DutPulseCtrOn && fm2014.RefPulseCtrOn)
{
// Synchronized backup of REF and DUT pulse counter
Write(CmdName.CMD_REF_DUT_BU_PLS_CTR, fm2014);
}
// Synchronized backup of REF and DUT pulse counter
Write(CmdName.CMD_REF_DUT_BU_PLS_CTR, this);
}
foreach (var fm2014 in RegisteredFm2014s.Where(fm2014 => fm2014.IsLoggedOn))
{
if (SharedCyclicMeasSequ != CyclicMeasSequ.IDLE)
{
if (fm2014.RefPulseCtrOn && Write(cmdNameRef, fm2014))
@ -878,12 +884,12 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
}
}
}
catch (Exception e)
{
var response = new CmdResponse(cmdName, e.Message);
PublishResponse(fm2014, new ProcessExecEventArgs(Resources.StrError,
specificInfoObj: response, statusReturn: StatusReturn.Failed));
}
}
catch (Exception e)
{
var response = new CmdResponse(cmdName, e.Message);
PublishResponse(this, new ProcessExecEventArgs(Resources.StrError,
specificInfoObj: response, statusReturn: StatusReturn.Failed));
}
} while (SharedCyclicMeasSequ != CyclicMeasSequ.IDLE);
}, SharedCancellationToken).ContinueWith(delegate
@ -1274,7 +1280,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
var info = GetCmdInfo(cmdName);
Attenuation = attenuation;
var response = new CmdResponse(cmdName, info, Attenuation);
PublishResponse(this, new ProcessExecEventArgs("",
PublishResponse(this, new ProcessExecEventArgs("",
actualProcessMessage: measurementInfoStr, specificInfoObj: response));
}
}
@ -1338,7 +1344,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// <remarks date="2026-Jan-08" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
/// <remarks date="2026-Jan-28" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-28..30" author="Thomas Wiedebusch">
/// - Support for multiple FM2014s.
/// </remarks>
public Boolean Login()
@ -1379,7 +1385,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
if (Read(cmdName, this, out responseStr))
{
var cleanedResponse = Regex.Replace(responseStr, "[^0-9]", string.Empty);
if (int.TryParse(cleanedResponse, /*NumberStyles.HexNumber, new CultureInfo("en"),*/ out var intValue))
if (int.TryParse(cleanedResponse, out var intValue))
Lifetime_h = intValue;
}

View File

@ -611,7 +611,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Pr
}
/// <summary>
/// Looks up a localized string similar to Setup.
/// Looks up a localized string similar to Command.
/// </summary>
internal static string StrCommDirectionSetup {
get {

View File

@ -298,7 +298,7 @@
<value>Verbinde mit Adresse</value>
</data>
<data name="StrCommDirectionSetup" xml:space="preserve">
<value>Einstellung</value>
<value>Befehl</value>
</data>
<data name="StrCommDirectionRequest" xml:space="preserve">
<value>Abfrage</value>

View File

@ -298,7 +298,7 @@
<value>Connect to address</value>
</data>
<data name="StrCommDirectionSetup" xml:space="preserve">
<value>Setup</value>
<value>Command</value>
</data>
<data name="StrCommDirectionRequest" xml:space="preserve">
<value>Request</value>

View File

@ -530,6 +530,7 @@ namespace Sensus.MiniPrf.Ui
var dt = DateTime.UtcNow;
var msg = $"{dt:yyyy-MM-dd HH:mm:ss} UTC";
LogText($"{Resources.StrMsgPcDateTime} {msg}");
LogText(StrSeparator);
CheckUpdateEnabled();
}));
@ -833,7 +834,7 @@ namespace Sensus.MiniPrf.Ui
if (cbxMultipleFm2014.Checked)
{
// Just take the DUT pulses as REF is parallel to all devices
Fm2014_TEST.PulseCounterMeasurement(false, true);
Fm2014_TEST?.PulseCounterMeasurement(false, true);
}
}
@ -1245,7 +1246,7 @@ namespace Sensus.MiniPrf.Ui
}
}
#endregion Buttons and Controls
#endregion Buttons and Controls
#region Event handler
@ -1377,7 +1378,7 @@ namespace Sensus.MiniPrf.Ui
}
/// <summary>
/// Feedback from FM2014being parsed to GUI
/// Feedback from FM2014 TEST device being logged to history window
/// </summary>
/// <remarks date="2023-Jan-30" author="Thomas Wiedebusch">
/// - Initial.