FM2014: - prepared for multiple FM2014s - 3.Step

This commit is contained in:
Thomas Wiedebusch 2026-01-30 09:15:58 +01:00
parent 9918494a6f
commit 5c6302b2fe
2 changed files with 86 additions and 21 deletions

View File

@ -854,7 +854,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
out var intValue))
{
var response = new CmdResponse(cmdNameDut, infoDut, intValue);
OnRawRecordReceived?.Invoke(fm2014,
fm2014.OnRawRecordReceived?.Invoke(fm2014,
new ProcessExecEventArgs("", actualProcessMessage: measurementInfoStr,
specificInfoObj: response));
}
@ -869,7 +869,17 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
}
}
} while (SharedCyclicMeasSequ != CyclicMeasSequ.IDLE);
}, SharedCancellationToken);
}, SharedCancellationToken).ContinueWith(delegate
{
foreach (var fm2014 in RegisteredFm2014s)
{
if (fm2014 != null)
{
fm2014.DutPulseCtrOn = false;
fm2014.RefPulseCtrOn = false;
}
}
});
return true;
}
@ -1267,7 +1277,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
specificInfoObj: response));
}
}
if (str.Contains(StandAlonePartSearchDutPpvStr))
{
var strCleaned = Regex.Replace(str, "[^0-9]", string.Empty);
@ -1367,18 +1377,15 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// <remarks date="2026-Jan-27" author="Thomas Wiedebusch">
/// - Delayed reset to allow other tasks to finish.
/// </remarks>
/// <remarks date="2026-Jan-28..29" author="Thomas Wiedebusch">
/// <remarks date="2026-Jan-28..30" author="Thomas Wiedebusch">
/// - Support for multiple FM2014s.
/// </remarks>
public Boolean ResetMeasurement()
{
// Reset pulse counter activity
RefPulseCtrOn = false;
DutPulseCtrOn = false;
if (SharedCyclicMeasSequ == CyclicMeasSequ.IDLE)
return true;
// Exit tasks
SharedCyclicMeasSequ = CyclicMeasSequ.IDLE;
// Schedule to other tasks to avoid side effects through the reset command
@ -1471,13 +1478,10 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
/// </remarks>
public Boolean Logout()
{
// Close only if all FM2014 instances are removed
ResetMeasurement();
IsLoggedOn = false;
SharedCmdTypeReminderLastCmd = CmdType.NOT_INITIALIZED;
if (RegisteredFm2014s == null || RegisteredFm2014s.Count == 0)
SharedSerialPort?.Close();
return SharedSerialPort != null && !SharedSerialPort.IsOpen;
return true;
}
/// <summary>
@ -1489,6 +1493,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
public void Dispose()
{
Logout();
ResetMeasurement();
RegisteredFm2014s?.Clear();
RegisteredFm2014s = null;
SharedSerialPort?.Dispose();

View File

@ -33,6 +33,8 @@
*=======================================================================================\n
*/
//#define TEST_MULTIPLE_FM2014
using Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Config;
using Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core;
using Sensus.MiniPrf.Ui.Properties;
@ -52,6 +54,8 @@ using Xylem.Common.Utils.ProcessExec.EventArguments;
namespace Sensus.MiniPrf.Ui
{
/// <summary>
/// Main form for 'MiniPrf'
/// </summary>
@ -59,6 +63,8 @@ namespace Sensus.MiniPrf.Ui
{
#region Properties
// DEBUG to test multiple objects of FM2014
// cancellation token
private CancellationTokenSource _cancellationTokenSource;
private CancellationToken _cancellationToken;
@ -68,10 +74,13 @@ namespace Sensus.MiniPrf.Ui
/// </summary>
private FM2014 Fm2014 { get; set; }
#if TEST_MULTIPLE_FM2014
//TODO THW TEST FM2014 multiple objects
/// <summary>
/// The single FM2014 for this program
/// </summary>
private FM2014 Fm2014_TEST { get; set; }
#endif
/// <summary>
/// The start time is going to be used for time measurements of processes. It has to be set to
@ -446,12 +455,7 @@ namespace Sensus.MiniPrf.Ui
//assign new meter
Fm2014 = new FM2014();
//TODO THW TEST FM2014 multiple objects
Fm2014_TEST = new FM2014();
Fm2014_TEST.Address = 2;
Fm2014_TEST.OnRawRecordReceived += DataReceived_Handler;
Fm2014.OnRawRecordReceived += DataReceived_Handler;
Fm2014.OnRawRecordReceived += DataReceived_Handler;
ResetCancellationToken();
FM2014.SharedCancellationToken = _cancellationToken;
if (int.TryParse(cbxFM2014Address.SelectedItem.ToString(), out var address))
@ -477,15 +481,24 @@ namespace Sensus.MiniPrf.Ui
lblActualProcess.Text = Resources.StrMsgConnecting;
Fm2014.Connect(cbxFM2014ComPort.SelectedItem.ToString());
#if TEST_MULTIPLE_FM2014
//TODO THW TEST FM2014 multiple objects
Fm2014_TEST = new FM2014
{
Address = 2
};
Fm2014_TEST.OnRawRecordReceived += DataReceived_Handler_TEST;
Fm2014_TEST.Connect(cbxFM2014ComPort.SelectedItem.ToString());
#endif
Task.Factory.StartNew(() =>
{
Fm2014.Login();
#if TEST_MULTIPLE_FM2014
//TODO THW TEST FM2014 multiple objects
Fm2014_TEST.Login();
#endif
if (!Fm2014.IsLoggedOn)
{
@ -533,7 +546,7 @@ namespace Sensus.MiniPrf.Ui
}
}
#endregion BoardControls
#endregion BoardControls
#region ProcessControls
@ -807,11 +820,18 @@ namespace Sensus.MiniPrf.Ui
_backupWeightScaleVolumeLitersStr = "";
_autoProgressBar = true;
if (Fm2014.PulseCounterMeasurement(true, true))
{
btnManualRefCalibration.Text = Resources.StrBtnStopCalibration;
btnManualRefCalibration.Enabled = true;
}
#if TEST_MULTIPLE_FM2014
//TODO THW TEST FM2014 multiple objects
Fm2014_TEST.PulseCounterMeasurement(false, true);
#endif
}
else
{
@ -1221,7 +1241,7 @@ namespace Sensus.MiniPrf.Ui
}
}
#endregion Buttons and Controls
#endregion Buttons and Controls
#region Event handler
@ -1293,6 +1313,7 @@ namespace Sensus.MiniPrf.Ui
tbxRefFrequencyHz.BackColor = ColorStandardDisplayField;
tbxActualFlowRateCmPerHour.BackColor = ColorStandardDisplayField;
}
break;
}
}
@ -1313,6 +1334,7 @@ namespace Sensus.MiniPrf.Ui
{
tbxActualMeasuredToleranceDutToRef.BackColor = ColorStandardDisplayField;
}
break;
case FM2014CmdDef.CmdName.CMD_REF_SET_SCALE:
tbxScaleRefToDut.Text = $@"{resp.DoubleValue:F4}";
@ -1344,11 +1366,49 @@ namespace Sensus.MiniPrf.Ui
}
}
// Catch the latest information
Update();
}));
}
#if TEST_MULTIPLE_FM2014
/// <summary>
/// Feedback from FM2014being parsed to GUI
/// </summary>
/// <remarks date="2023-Jan-30" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
//TODO THW TEST FM2014 multiple objects
private void DataReceived_Handler_TEST(Object sender, ProcessExecEventArgs e)
{
Invoke(new Action(() =>
{
// Data dispatcher
var resp = (FM2014CmdDef.CmdResponse)e.SpecificInfoObj;
if (e.StatusReturn == StatusReturn.Failed)
{
LogErrorText(resp.AnswerStr);
//ErrorHandler(resp.CmdName);
}
else if (resp.IntValue == null && resp.DoubleValue == null)
{
LogText(resp.AnswerStr);
}
else if (resp.IntValue != null)
{
LogText($"{resp.AnswerStr}: {resp.IntValue:D} {resp.SiUnit}");
}
else if (resp.DoubleValue != null)
{
LogText($"{resp.AnswerStr}: {resp.DoubleValue:F2} {resp.SiUnit}");
}
}));
}
#endif
#endregion
}