diff --git a/FM2014TestApp/Ui/FM2014TestbenchWpf/FM2014TestBenchWindow.xaml b/FM2014TestApp/Ui/FM2014TestbenchWpf/FM2014TestBenchWindow.xaml
index fb59a5a3..5c38fca2 100644
--- a/FM2014TestApp/Ui/FM2014TestbenchWpf/FM2014TestBenchWindow.xaml
+++ b/FM2014TestApp/Ui/FM2014TestbenchWpf/FM2014TestBenchWindow.xaml
@@ -21,11 +21,11 @@
-
@@ -129,19 +129,103 @@
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FM2014TestApp/Ui/FM2014TestbenchWpf/FM2014TestBenchWindow.xaml.cs b/FM2014TestApp/Ui/FM2014TestbenchWpf/FM2014TestBenchWindow.xaml.cs
index f677f7bd..4b804364 100644
--- a/FM2014TestApp/Ui/FM2014TestbenchWpf/FM2014TestBenchWindow.xaml.cs
+++ b/FM2014TestApp/Ui/FM2014TestbenchWpf/FM2014TestBenchWindow.xaml.cs
@@ -42,8 +42,10 @@ using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
+using Sensus.Ui.FM2014TestBench.UserControls;
using Xylem.Common.CommonCore.Consts;
using Xylem.Common.Utils.ProcessExec.EventArguments;
+using static Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Consts.FM2014CmdDef;
namespace Sensus.Ui.FM2014TestBench
{
@@ -57,10 +59,22 @@ namespace Sensus.Ui.FM2014TestBench
private CancellationTokenSource _cancellationTokenSource;
private CancellationToken _cancellationToken;
+ private const Int32 MaxFm2014s = 10;
+
///
/// The FM2014s served by this program
///
- private List Fm2014s { get; set; }
+ private readonly List Fm2014s = [];
+
+ ///
+ /// Stack panels for UcFM2014Device
+ ///
+ private readonly List PanelsForUcFM2014s = [];
+
+ ///
+ /// User controls of FM2014Device
+ ///
+ private readonly List UcFM2014s = [];
///
/// The start time is going to be used for time measurements of processes. It has to be set to
@@ -136,6 +150,7 @@ namespace Sensus.Ui.FM2014TestBench
_cancellationTokenSource = new CancellationTokenSource();
_cancellationToken = _cancellationTokenSource.Token;
+
}
private void Window_Loaded(Object sender, RoutedEventArgs e)
@@ -144,12 +159,6 @@ namespace Sensus.Ui.FM2014TestBench
// OnLogin_Click(this, null);
}
- //TODO THW TEST FM2014 multiple objects
- ///
- /// The single FM2014 for this program
- ///
- private FM2014 Fm2014_TEST { get; set; }
-
private void Window_Initialized(Object sender, EventArgs e)
{
Init();
@@ -162,18 +171,56 @@ namespace Sensus.Ui.FM2014TestBench
LogText(StrSeparator);
}
- ////btnFM2014Connect.Focus();
- ////TODO THW TEST FM2014 multiple objects
- //Fm2014_TEST = new FM2014
- //{
- // Address = 1
- //};
- //Fm2014_TEST.OnRawRecordReceived += DataReceived_Handler;
- //Fm2014_TEST.Connect("COM23");
- //Fm2014_TEST.Login();
+ // Add user controls
+ // Initiate the stack panels
+ PanelsForUcFM2014s.Add(spDevice1);
+ PanelsForUcFM2014s.Add(spDevice2);
+ PanelsForUcFM2014s.Add(spDevice3);
+ PanelsForUcFM2014s.Add(spDevice4);
+ PanelsForUcFM2014s.Add(spDevice5);
+ PanelsForUcFM2014s.Add(spDevice6);
+ PanelsForUcFM2014s.Add(spDevice7);
+ PanelsForUcFM2014s.Add(spDevice8);
+ PanelsForUcFM2014s.Add(spDevice9);
+ PanelsForUcFM2014s.Add(spDevice10);
+ // Assign user controls
+ for (var ctr = 0; ctr < MaxFm2014s; ctr++)
+ {
+ var fm2014 = new FM2014
+ {
+ Address = ctr + 1
+ };
+
+ fm2014.OnRawRecordReceived += DataReceived_Handler;
+ Fm2014s.Add(fm2014);
+ UcFM2014s.Add(new UserControls.UcFM2014Device(Fm2014s[ctr]));
+ SetNewUserControl(PanelsForUcFM2014s[ctr], UcFM2014s[ctr]);
+ }
}
+ ///
+ /// Dispatch new user control to main screen
+ ///
+ ///
+ ///
+ private void SetNewUserControl(StackPanel sp, UserControl? uc)
+ {
+ sp.Dispatcher.Invoke(DispatcherPriority.Normal,
+ new Action(() =>
+ {
+ // remove last userControl
+ sp.Children.Clear();
+ if (uc != null)
+ {
+ sp.Children.Add(uc);
+ DockPanel.SetDock(uc, Dock.Top); // & Dock.Left);
+ }
+ }
+ ));
+ }
+
+
private void Window_Closing(Object sender, System.ComponentModel.CancelEventArgs e)
{
_cancellationTokenSource.Cancel();
@@ -490,123 +537,93 @@ namespace Sensus.Ui.FM2014TestBench
///
private void Connect()
{
- //try
- //{
- // Init();
- // if (string.IsNullOrEmpty(cbxFM2014ComPort?.SelectedItem?.ToString()) ||
- // cbxFM2014ComPort.SelectedItem.ToString().Equals("?"))
- // {
- // var text = Resources.StrErrorMsgComPortNotAssigned;
- // MessageBox.Show(text, Resources.StrError, MessageBoxButtons.OK, MessageBoxIcon.Error);
- // LogText(text);
- // return;
- // }
+ try
+ {
+ Init();
+ //if (string.IsNullOrEmpty(cbxFM2014ComPort?.SelectedItem?.ToString()) ||
+ // cbxFM2014ComPort.SelectedItem.ToString().Equals("?"))
+ //{
+ // var text = Resources.StrErrorMsgComPortNotAssigned;
+ // MessageBox.Show(text, Resources.StrError, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ // LogText(text);
+ // return;
+ //}
- // StoreFM2014Settings();
+ StoreFM2014Settings();
- // ActionControl(true);
+ ActionControl(true);
- // if (Fm2014 != null)
- // {
- // Fm2014.OnRawRecordReceived -= DataReceived_Handler;
- // Fm2014.Dispose();
- // //dispose old meter
- // Fm2014 = null;
- // }
+ ResetCancellationToken();
+ FM2014.SharedCancellationToken = _cancellationToken;
+ //lblActualProcess.Text = Resources.StrMsgConnecting;
+ //Fm2014.Connect(cbxFM2014ComPort.SelectedItem.ToString());
- // //assign new meter
- // Fm2014 = new FM2014();
+ var comPort = "COM23";
- // Fm2014.OnRawRecordReceived += DataReceived_Handler;
- // ResetCancellationToken();
- // FM2014.SharedCancellationToken = _cancellationToken;
- // if (int.TryParse(cbxFM2014Address.SelectedItem.ToString(), out var address))
- // {
- // Fm2014.Address = address;
- // }
- // else
- // {
- // ActionControl(false);
- // LogErrorText(Resources.StrErrorMsgFM2014AddressInvalid);
- // }
- // if (int.TryParse(cbxFM2014TolerancePercent.SelectedItem.ToString(), out var tolerancePercent)
- // && (tolerancePercent == 3 || tolerancePercent == 5))
- // {
- // Fm2014.Tolerance_percent = tolerancePercent;
- // }
- // else
- // {
- // ActionControl(false);
- // LogErrorText(Resources.StrErrorMsgFM2014ToleranceInvalid);
- // }
+ Task.Factory.StartNew(() =>
+ {
+ for (var ctr = 0; ctr < MaxFm2014s; ctr++)
+ {
+ var ucFm2014Device = (UcFM2014Device)UcFM2014s[ctr];
+ var fm2014 = Fm2014s[ctr];
- // lblActualProcess.Text = Resources.StrMsgConnecting;
- // Fm2014.Connect(cbxFM2014ComPort.SelectedItem.ToString());
+ if (!fm2014.Connect(comPort))
+ {
+ ucFm2014Device.SetConnectionStatus(ConnectionStatusName.OFFLINE);
+ continue;
+ }
+ fm2014.Login();
- // //TODO THW TEST FM2014 multiple objects
- // if (cbxMultipleFm2014.Checked)
- // {
- // Fm2014_TEST = new FM2014
- // {
- // Address = 2
- // };
- // Fm2014_TEST.OnRawRecordReceived += DataReceived_Handler_TEST;
- // Fm2014_TEST.Connect(cbxFM2014ComPort.SelectedItem.ToString());
- // }
+ if (fm2014.IsLoggedOn)
+ {
+ ucFm2014Device.SetConnectionStatus(ConnectionStatusName.ONLINE);
+ }
+ else
+ {
+ ucFm2014Device.SetConnectionStatus(ConnectionStatusName.OFFLINE);
+ }
+ }
+ //if (!Fm2014.IsLoggedOn)
+ //{
+ // LogErrorText(Resources.StrErrorMsgFM2014AccessDenied);
+ // ActionControl(false);
+ // return;
+ //}
- // Task.Factory.StartNew(() =>
- // {
- // Fm2014.Login();
+ //if (Fm2014.IsLoggedOn)
+ //{
+ // Invoke(new Action(() =>
+ // {
+ // lblConnectionStatus.Text = Resources.StrLblFM2014Connected;
+ // lblConnectionStatus.ForeColor = Color.Green;
+ // tbxFM2014ApplicationFwVersion.Text = Fm2014.FwVersion;
+ // tbxFM2014SerialNumber.Text = Fm2014.SerialNumber;
- // //TODO THW TEST FM2014 multiple objects
- // if (cbxMultipleFm2014.Checked)
- // {
- // Fm2014_TEST.Login();
- // }
+ // // Logging to history window
+ // LogText("FM2014 ID: " + Fm2014.ConnectResponse);
+ // LogText("FM2014 Firmware Version: " + Fm2014.FwVersion);
+ // LogText($"FM2014 {Resources.StrLblFM2014SerialNumber} " + Fm2014.SerialNumber);
+ // LogText($"FW2014 {Resources.StrLblFM2014Address} " + Fm2014.Address);
+ // var dt = DateTime.UtcNow;
+ // var msg = $"{dt:yyyy-MM-dd HH:mm:ss} UTC";
+ // LogText($"{Resources.StrMsgPcDateTime} {msg}");
+ // LogText(StrSeparator);
- // if (!Fm2014.IsLoggedOn)
- // {
- // LogErrorText(Resources.StrErrorMsgFM2014AccessDenied);
- // Fm2014.Logout();
- // ActionControl(false);
-
- // return;
- // }
-
- // if (Fm2014.IsLoggedOn)
- // {
- // Invoke(new Action(() =>
- // {
- // lblConnectionStatus.Text = Resources.StrLblFM2014Connected;
- // lblConnectionStatus.ForeColor = Color.Green;
- // tbxFM2014ApplicationFwVersion.Text = Fm2014.FwVersion;
- // tbxFM2014SerialNumber.Text = Fm2014.SerialNumber;
-
- // // Logging to history window
- // LogText("FM2014 ID: " + Fm2014.ConnectResponse);
- // LogText("FM2014 Firmware Version: " + Fm2014.FwVersion);
- // LogText($"FM2014 {Resources.StrLblFM2014SerialNumber} " + Fm2014.SerialNumber);
- // LogText($"FW2014 {Resources.StrLblFM2014Address} " + Fm2014.Address);
- // var dt = DateTime.UtcNow;
- // var msg = $"{dt:yyyy-MM-dd HH:mm:ss} UTC";
- // LogText($"{Resources.StrMsgPcDateTime} {msg}");
- // LogText(StrSeparator);
-
- // CheckUpdateEnabled();
- // }));
- // }
- // }, _cancellationToken).ContinueWith(delegate
- // {
- // ActionControl(false);
- // }, _cancellationToken);
- //}
- //catch (Exception ex)
- //{
- // ActionControl(false);
- // MessageBox.Show(ex.Message, Resources.StrError, MessageBoxButtons.OK, MessageBoxIcon.Error);
- // LogErrorText(ex.Message);
- // Fm2014?.Dispose();
- //}
+ // CheckUpdateEnabled();
+ // }));
+ //}
+ }, _cancellationToken).ContinueWith(delegate
+ {
+ ActionControl(false);
+ }, _cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ ActionControl(false);
+ //MessageBox.Show(ex.Message, Resources.StrError, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ LogErrorText(ex.Message);
+ //Fm2014?.Dispose();
+ }
}
#endregion BoardControls
@@ -885,7 +902,7 @@ namespace Sensus.Ui.FM2014TestBench
private void btnConnect_Click(Object sender, EventArgs e)
{
_startTime = DateTimeOffset.UtcNow;
- //Connect();
+ Connect();
}
///
@@ -1387,6 +1404,11 @@ namespace Sensus.Ui.FM2014TestBench
///
private void DataReceived_Handler(Object? sender, ProcessExecEventArgs e)
{
+ Int32 address = 0;
+ if (sender is FM2014 fm2014)
+ {
+ address = fm2014.Address;
+ }
// Progress info section
if (e.ActualProcessMessage != null)
{
diff --git a/FM2014TestApp/Ui/FM2014TestbenchWpf/UserControls/UcFM2014Device.xaml b/FM2014TestApp/Ui/FM2014TestbenchWpf/UserControls/UcFM2014Device.xaml
index d05fbe71..bec547b3 100644
--- a/FM2014TestApp/Ui/FM2014TestbenchWpf/UserControls/UcFM2014Device.xaml
+++ b/FM2014TestApp/Ui/FM2014TestbenchWpf/UserControls/UcFM2014Device.xaml
@@ -8,45 +8,45 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
diff --git a/FM2014TestApp/Ui/FM2014TestbenchWpf/UserControls/UcFM2014Device.xaml.cs b/FM2014TestApp/Ui/FM2014TestbenchWpf/UserControls/UcFM2014Device.xaml.cs
index 896d9283..b422bc8b 100644
--- a/FM2014TestApp/Ui/FM2014TestbenchWpf/UserControls/UcFM2014Device.xaml.cs
+++ b/FM2014TestApp/Ui/FM2014TestbenchWpf/UserControls/UcFM2014Device.xaml.cs
@@ -30,9 +30,11 @@
*
*=======================================================================================\n
*/
+
using System.Windows;
+using System.Windows.Controls;
using System.Windows.Threading;
-using Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Consts;
+using Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core;
using static Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core.Consts.FM2014CmdDef;
namespace Sensus.Ui.FM2014TestBench.UserControls
@@ -43,25 +45,29 @@ namespace Sensus.Ui.FM2014TestBench.UserControls
public partial class UcFM2014Device : IUserControl
{
- ///
- /// Switches between picture or measurement fields
- ///
- private Boolean MeasurementIsActive { set; get; }
+ /////
+ ///// Switches between picture or measurement fields
+ /////
+ //private Boolean MeasurementIsActive { set; get; }
- private List MeasurementBorders;
- private List MeasurementLabels;
+ private readonly List MeasurementBorders;
+ private readonly List MeasurementLabels;
+
+ private readonly FM2014 _fM2014;
///
/// Ctor
///
+ ///
///
/// - Initial.
///
- public UcFM2014Device()
+ public UcFM2014Device(FM2014 fm2014)
{
InitializeComponent();
- MeasurementBorders = new List();
- MeasurementLabels = new List();
+ _fM2014 = fm2014;
+ MeasurementBorders = [];
+ MeasurementLabels = [];
MeasurementBorders.Add(brdMeasurement1);
MeasurementBorders.Add(brdMeasurement2);
MeasurementBorders.Add(brdMeasurement3);
@@ -83,9 +89,38 @@ namespace Sensus.Ui.FM2014TestBench.UserControls
public void Clear()
{
SetConnectionStatus(ConnectionStatusName.OFFLINE);
+ HideMeasurements();
+ }
+
+ ///
+ /// Set a value to a label
+ ///
+ ///
+ ///
+ ///
+ public Boolean SetValue(Int32 labelNumber, String valueStr)
+ {
+ var index = labelNumber - 1;
+ if (index < 0 || labelNumber > MeasurementLabels.Count ||
+ !MeasurementLabels[index].IsEnabled)
+ return false;
+
+ var label = (Label)MeasurementLabels[index];
+ UpdateValue(label, valueStr);
+ return true;
+ }
+
+ ///
+ /// Hide measurements and switch back to display the picture of FM2014
+ ///
+ ///
+ /// - Initial.
+ ///
+ private void HideMeasurements()
+ {
UiElmEnable(brdFM2014Pic, true);
- // Initially the device is NOT connected
- UiElmEnable(picFM2014, false);
+ UiElmEnable(picFM2014, lblStatus.Content.Equals(ConnectionStatusName.ONLINE));
+
// Hide all measurement borders
foreach (var borders in MeasurementBorders)
{
@@ -103,6 +138,9 @@ namespace Sensus.Ui.FM2014TestBench.UserControls
///
/// 1..7
///
+ ///
+ /// - Initial.
+ ///
public Boolean EnableMeasurements(UInt32 numberOfMeasurementFields)
{
// Check if device is connected and logged in
@@ -110,6 +148,19 @@ namespace Sensus.Ui.FM2014TestBench.UserControls
numberOfMeasurementFields == 0)
return false;
+ //MeasurementIsActive = true;
+ // Hide the picture and the border of it
+ UiElmEnable(picFM2014, false, false);
+ UiElmEnable(brdFM2014Pic, false, false);
+
+ // Display the measurement fields
+ for (var ctr = 0; ctr < numberOfMeasurementFields; ctr++)
+ {
+ if (ctr > MeasurementBorders.Count)
+ break;
+ UiElmEnable(MeasurementBorders[ctr], true);
+ UiElmEnable(MeasurementLabels[ctr], true);
+ }
return true;
}
@@ -117,6 +168,9 @@ namespace Sensus.Ui.FM2014TestBench.UserControls
/// Refresh connection status
///
///
+ ///
+ /// - Initial.
+ ///
public void SetConnectionStatus(ConnectionStatusName statusName)
{
var connectionStatusStr = GetConnectionStatusInfo(statusName);
@@ -124,14 +178,63 @@ namespace Sensus.Ui.FM2014TestBench.UserControls
new Action(() =>
{
lblStatus.Content = connectionStatusStr;
+ var isEnabled = statusName.Equals(ConnectionStatusName.ONLINE);
+ UiElmEnable(picFM2014, isEnabled);
if (!statusName.Equals(ConnectionStatusName.ONLINE))
{
- brdFM2014Pic.Visibility = Visibility.Visible;
- picFM2014.Visibility = Visibility.Visible;
- picFM2014.IsEnabled = false;
+ HideMeasurements();
+ }
+ else
+ {
+
+ lblLifetime_h.Content = _fM2014.Lifetime_h;
+ lblFirmwareVersion.Content = _fM2014.FwVersion;
+ lblSerialNumber.Content = _fM2014.SerialNumber;
}
}
- ));
+ ));
+ }
+
+ ///
+ /// Output message to control without access violation.
+ ///
+ ///
+ ///
+ /// - Initial
+ ///
+ ///
+ /// - Introduced multi line text with center alignment.
+ ///
+ private static void UpdateContentControl(ContentControl ctl, String text)
+ {
+ ctl.Dispatcher.Invoke(DispatcherPriority.Normal,
+ new Action(() =>
+ {
+ ctl.Content = new TextBlock()
+ {
+ Text = text,
+ TextWrapping = TextWrapping.Wrap,
+ TextAlignment = TextAlignment.Center
+ };
+ }
+ ));
+ }
+
+ ///
+ /// Publish value to label
+ ///
+ ///
+ ///
+ ///
+ /// - Initial.
+ ///
+ private void UpdateValue(Label label, String valueStr)
+ {
+ Dispatcher.Invoke(DispatcherPriority.Normal,
+ new Action(() =>
+ {
+ label.Content = valueStr ;
+ }));
}
///
@@ -140,16 +243,15 @@ namespace Sensus.Ui.FM2014TestBench.UserControls
///
///
///
- public void UiElmEnable(UIElement elm, Boolean isEnabled, Boolean isVisible = true)
+ private static void UiElmEnable(UIElement elm, Boolean isEnabled, Boolean isVisible = true)
{
elm.Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(() =>
{
elm.Visibility = isVisible ? Visibility.Visible : Visibility.Hidden;
elm.IsEnabled = isEnabled;
-
+ elm.Opacity = isEnabled ? 1.0 : 0.2;
}));
}
-
}
}