diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs
index ad3545ab..414187a8 100644
--- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs
+++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs
@@ -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
///
/// - Delayed reset to allow other tasks to finish.
///
- ///
+ ///
/// - Support for multiple FM2014s.
///
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
///
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;
}
///
@@ -1489,6 +1493,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core
public void Dispose()
{
Logout();
+ ResetMeasurement();
RegisteredFm2014s?.Clear();
RegisteredFm2014s = null;
SharedSerialPort?.Dispose();
diff --git a/MiniPrf/Ui/FrmMainMiniPrf.cs b/MiniPrf/Ui/FrmMainMiniPrf.cs
index f21f6959..434f961d 100644
--- a/MiniPrf/Ui/FrmMainMiniPrf.cs
+++ b/MiniPrf/Ui/FrmMainMiniPrf.cs
@@ -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
{
+
+
///
/// Main form for 'MiniPrf'
///
@@ -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
///
private FM2014 Fm2014 { get; set; }
+ #if TEST_MULTIPLE_FM2014
+ //TODO THW TEST FM2014 multiple objects
///
/// The single FM2014 for this program
///
private FM2014 Fm2014_TEST { get; set; }
+ #endif
///
/// 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
+ ///
+ /// Feedback from FM2014being parsed to GUI
+ ///
+ ///
+ /// - Initial.
+ ///
+ //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
}