From 86919dc24020229cbd1d8c59f29a4a36895f5b7a Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 29 Jul 2018 13:03:22 +0300 Subject: Implemented diagnostics frame rate monitor on IDiagnosticsFrameProvider. Added diagnostics frame rate to connected machine dialog. Implemented dynamic graphs max points using frame rate on tech board!. Implemented speed control on DIagnosticsFilePlayer & Data Capture module. Implemented graphs duration control on tech board. --- .../ViewModels/MachineTechViewVM.cs | 98 ++++++++++++++++++++-- 1 file changed, 89 insertions(+), 9 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index d403223ec..3dff65fbc 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -43,6 +43,7 @@ namespace Tango.MachineStudio.Technician.ViewModels public class MachineTechViewVM : StudioViewModel { private List _diagnoticsMonitorsDataProperties; + private IDiagnosticsFrameProvider _diagnosticsFrameProvider; private Dictionary _singleControllers; private Dictionary _multiControllers; private static object _elementsLock = new object(); @@ -149,6 +150,28 @@ namespace Tango.MachineStudio.Technician.ViewModels set { _currentDiagnosticsResponseSize = value; RaisePropertyChanged(nameof(CurrentDiagnosticsResponseSize)); } } + private int _graphsDurationSeconds; + /// + /// Gets or sets the graphs duration seconds. + /// + public int GraphsDurationSeconds + { + get { return _graphsDurationSeconds; } + set { _graphsDurationSeconds = value; RaisePropertyChangedAuto(); } + } + + private int _tempGraphsDurationSeconds; + /// + /// Gets or sets the temporary graphs duration seconds. + /// + public int TempGraphsDurationSeconds + { + get { return _tempGraphsDurationSeconds; } + set { _tempGraphsDurationSeconds = value; RaisePropertyChangedAuto(); } + } + + + #endregion #region Commands @@ -183,6 +206,8 @@ namespace Tango.MachineStudio.Technician.ViewModels /// public RelayCommand ResetHardwareConfigurationCommand { get; set; } + public RelayCommand UpdateGraphsDurationCommand { get; set; } + #endregion #region Constructors @@ -192,10 +217,13 @@ namespace Tango.MachineStudio.Technician.ViewModels /// /// The application manager. /// The notification provider. - public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider _diagnosticsFrameProvider, IEventLogger eventLogger) + public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IEventLogger eventLogger) { _settings = SettingsManager.Default.GetOrCreate(); + GraphsDurationSeconds = _settings.GraphsDuration; + TempGraphsDurationSeconds = GraphsDurationSeconds; + _notification = notificationProvider; _eventLogger = eventLogger; _singleControllers = new Dictionary(); @@ -217,14 +245,28 @@ namespace Tango.MachineStudio.Technician.ViewModels if (File.Exists(_lastTechProjectFile)) { - OpenProjectFile(_lastTechProjectFile); + try + { + OpenProjectFile(_lastTechProjectFile); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading last project file."); + } } + _diagnosticsFrameProvider = diagnosticsFrameProvider; _diagnosticsFrameProvider.FrameReceived += DiagnosticsFrameProvider_FrameReceived; UploadHardwareConfigurationCommand = new RelayCommand(UploadHardwareConfiguration); SyncHardwareConfigurationCommand = new RelayCommand(SyncHardwareConfiguration); ResetHardwareConfigurationCommand = new RelayCommand(() => ResetHardwareConfiguration()); + UpdateGraphsDurationCommand = new RelayCommand(() => + { + GraphsDurationSeconds = TempGraphsDurationSeconds; + _settings.GraphsDuration = GraphsDurationSeconds; + ClearAllGraphs(); + }); } #endregion @@ -320,7 +362,16 @@ namespace Tango.MachineStudio.Technician.ViewModels if (_singleControllers.TryGetValue(graphItem, out controller)) { - controller.PushData(GetDataArray(graphItem.TechMonitor, prop.GetValue(data.Monitors))); + var points = GetDataArray(graphItem.TechMonitor, prop.GetValue(data.Monitors)); + + int maxPoints = (int)(_diagnosticsFrameProvider.FrameRate * GraphsDurationSeconds * points.Count); + + InvokeUI(() => + { + graphItem.Editor.InnerGraph.InnerGraph.MaxPoints = maxPoints; + }); + + controller.PushData(points); } } } @@ -336,7 +387,19 @@ namespace Tango.MachineStudio.Technician.ViewModels if (_multiControllers.TryGetValue(graphItem, out controller)) { - controller.PushData(GetDataMatrix(graphItem.TechMonitor, prop.GetValue(data.Monitors))); + var points = GetDataMatrix(graphItem.TechMonitor, prop.GetValue(data.Monitors)); + + if (points.Count > 0) + { + int maxPoints = (int)(_diagnosticsFrameProvider.FrameRate * GraphsDurationSeconds * points[0].Count); + + InvokeUI(() => + { + graphItem.Editor.InnerGraph.InnerGraph.MaxPoints = maxPoints; + }); + } + + controller.PushData(points); } } } @@ -1179,7 +1242,7 @@ namespace Tango.MachineStudio.Technician.ViewModels catch (Exception ex) { String msg = "Error uploading process parameters:" + Environment.NewLine + parameters.ToJsonString(); - _eventLogger.Log(ex,msg); + _eventLogger.Log(ex, msg); LogManager.Log(ex, msg); _notification.ShowError("Could not upload process parameters." + Environment.NewLine + ex.Message); } @@ -1199,7 +1262,7 @@ namespace Tango.MachineStudio.Technician.ViewModels /// private void InitJobRunnerItem(JobRunnerItem item) { - item.StartJob += () => + item.StartJob += () => { try { @@ -1209,12 +1272,12 @@ namespace Tango.MachineStudio.Technician.ViewModels item.JobHandler = handler; - handler.StatusChanged += (x, status) => + handler.StatusChanged += (x, status) => { item.RunningJobStatus = status; }; - handler.Stopped += (x,e) => + handler.Stopped += (x, e) => { item.IsJobStarted = false; }; @@ -1226,7 +1289,7 @@ namespace Tango.MachineStudio.Technician.ViewModels } }; - item.StopJob += () => + item.StopJob += () => { if (item.JobHandler != null) { @@ -1597,5 +1660,22 @@ namespace Tango.MachineStudio.Technician.ViewModels } #endregion + + #region Graphs + + public void ClearAllGraphs() + { + foreach (var controller in _singleControllers) + { + controller.Value.Clear(); + } + + foreach (var controller in _multiControllers) + { + controller.Value.Clear(); + } + } + + #endregion } } -- cgit v1.3.1