From ca293b80c52a54c73251fbf3cd50741fb5653ae9 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 15 Apr 2018 19:51:07 +0300 Subject: Lots Of Work ! --- .../ViewModels/MachineTechViewVM.cs | 400 ++++++++++++--------- 1 file changed, 230 insertions(+), 170 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels') 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 63aca3e70..88c50b549 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 @@ -29,6 +29,7 @@ using Tango.SharedUI; using Tango.Integration.Services; using Tango.BL.Enumerations; using Tango.BL; +using Tango.MachineStudio.Common.EventLogging; namespace Tango.MachineStudio.Technician.ViewModels { @@ -45,6 +46,7 @@ namespace Tango.MachineStudio.Technician.ViewModels private static object _elementsLock = new object(); private String _lastTechProjectFile; private INotificationProvider _notification; + private IEventLogger _eventLogger; private DateTime _lastDiagnosticsResponseUpdate; private const int MIN_DIAGNOSTICS_UPDATE_MILI = 500; @@ -171,9 +173,10 @@ namespace Tango.MachineStudio.Technician.ViewModels /// /// The application manager. /// The notification provider. - public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider _diagnosticsFrameProvider) + public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider _diagnosticsFrameProvider, IEventLogger eventLogger) { _notification = notificationProvider; + _eventLogger = eventLogger; _singleControllers = new Dictionary(); _multiControllers = new Dictionary(); AvailableTechItems = TechItem.GetAvailableTechItems().ToObservableCollection(); @@ -581,7 +584,8 @@ namespace Tango.MachineStudio.Technician.ViewModels else if (item is ControllerItem) { (item as ControllerItem).TechController = Adapter.TechControllers.FirstOrDefault(x => x.Guid == item.ItemGuid); - CreateElement(item); + var editor = CreateElement(item); + InitControllerItem(editor.ControllerItem); } } @@ -695,68 +699,78 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) - { - await MachineOperator.StartMotorJogging(new MotorJoggingRequest() - { - Code = item.TechMotor.Code, - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.ForwardReleased) + try { - await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = item.TechMotor.Code, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = item.TechMotor.Code, + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.ForwardReleased) { - Code = item.TechMotor.Code, - Direction = MotorDirection.Backward, - }); - } - else if (action == MotorActionType.BackwardReleased) - { - await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = item.TechMotor.Code, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Code = item.TechMotor.Code, - }); - } - else if (action == MotorActionType.HomingStarted) - { - item.HomingProgress = 0; - item.IsHoming = true; - item.IsHomingCompleted = false; - - MachineOperator.StartMotorHoming(new MotorHomingRequest() + await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = item.TechMotor.Code, + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.BackwardReleased) { - Code = item.TechMotor.Code - }) - .Subscribe((response) => + await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = item.TechMotor.Code, + }); + } + else if (action == MotorActionType.HomingStarted) { + item.HomingProgress = 0; + item.IsHoming = true; + item.IsHomingCompleted = false; - item.HomingMaximumProgress = response.MaxProgress; - item.HomingProgress = response.Progress; + MachineOperator.StartMotorHoming(new MotorHomingRequest() + { + Code = item.TechMotor.Code + }) + .Subscribe((response) => + { - }, () => + item.HomingMaximumProgress = response.MaxProgress; + item.HomingProgress = response.Progress; + + }, () => + { + + item.IsHoming = false; + item.IsHomingCompleted = true; + + }); + } + else if (action == MotorActionType.HomingStopped) { + await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + { + Code = item.TechMotor.Code, + }); item.IsHoming = false; - item.IsHomingCompleted = true; - - }); + } } - else if (action == MotorActionType.HomingStopped) + catch (Exception ex) { - await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() - { - Code = item.TechMotor.Code, - }); - - item.IsHoming = false; + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action,item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -769,68 +783,78 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) - { - await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() - { - Code = item.TechDispenser.Code, - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.ForwardReleased) + try { - await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = item.TechDispenser.Code, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + { + Code = item.TechDispenser.Code, + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.ForwardReleased) { - Code = item.TechDispenser.Code, - Direction = MotorDirection.Backward, - }); - } - else if (action == MotorActionType.BackwardReleased) - { - await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + { + Code = item.TechDispenser.Code, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Code = item.TechDispenser.Code, - }); - } - else if (action == MotorActionType.HomingStarted) - { - item.HomingProgress = 0; - item.IsHoming = true; - item.IsHomingCompleted = false; - - MachineOperator.StartDispenserHoming(new DispenserHomingRequest() + await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + { + Code = item.TechDispenser.Code, + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.BackwardReleased) { - Code = item.TechDispenser.Code - }) - .Subscribe((response) => + await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + { + Code = item.TechDispenser.Code, + }); + } + else if (action == MotorActionType.HomingStarted) { + item.HomingProgress = 0; + item.IsHoming = true; + item.IsHomingCompleted = false; - item.HomingMaximumProgress = response.MaxProgress; - item.HomingProgress = response.Progress; + MachineOperator.StartDispenserHoming(new DispenserHomingRequest() + { + Code = item.TechDispenser.Code + }) + .Subscribe((response) => + { + + item.HomingMaximumProgress = response.MaxProgress; + item.HomingProgress = response.Progress; + + }, () => + { + + item.IsHoming = false; + item.IsHomingCompleted = true; - }, () => + }); + } + else if (action == MotorActionType.HomingStopped) { + await MachineOperator.StopDispenserHoming(new DispenserAbortHomingRequest() + { + Code = item.TechDispenser.Code, + }); item.IsHoming = false; - item.IsHomingCompleted = true; - - }); + } } - else if (action == MotorActionType.HomingStopped) + catch (Exception ex) { - await MachineOperator.StopDispenserHoming(new DispenserAbortHomingRequest() - { - Code = item.TechDispenser.Code, - }); - - item.IsHoming = false; + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -886,23 +910,33 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) + try { - await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + { + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Direction = MotorDirection.Backward, - }); + await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + { + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.ForwardReleased || action == MotorActionType.BackwardReleased) + { + await MachineOperator.StopThreadJogging(new ThreadAbortJoggingRequest()); + } } - else if (action == MotorActionType.ForwardReleased || action == MotorActionType.BackwardReleased) + catch (Exception ex) { - await MachineOperator.StopThreadJogging(new ThreadAbortJoggingRequest()); + LogManager.Log(ex, String.Format(String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName))); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -915,69 +949,79 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) + try { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = motor.Code, - Direction = MotorDirection.Forward, - }))); - } - else if (action == MotorActionType.ForwardReleased) - { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Forward, + }))); + } + else if (action == MotorActionType.ForwardReleased) { - Code = motor.Code, - }))); - } - else if (action == MotorActionType.BackwardPressed) - { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + else if (action == MotorActionType.BackwardPressed) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Backward, + }))); + } + else if (action == MotorActionType.BackwardReleased) { - Code = motor.Code, - Direction = MotorDirection.Backward, - }))); + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + //else if (action == MotorActionType.HomingStarted) + //{ + // item.HomingProgress = 0; + // item.IsHoming = true; + // item.IsHomingCompleted = false; + + // MachineOperator.StartMotorHoming(new MotorHomingRequest() + // { + // Code = item.TechMotor.Code + // }) + // .Subscribe((response) => + // { + + // item.HomingMaximumProgress = response.Message.MaxProgress; + // item.HomingProgress = response.Message.Progress; + + // }, () => + // { + + // item.IsHoming = false; + // item.IsHomingCompleted = true; + + // }); + //} + //else if (action == MotorActionType.HomingStopped) + //{ + // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + // { + // Code = item.TechMotor.Code, + // }); + + // item.IsHoming = false; + //} } - else if (action == MotorActionType.BackwardReleased) + catch (Exception ex) { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() - { - Code = motor.Code, - }))); + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } - //else if (action == MotorActionType.HomingStarted) - //{ - // item.HomingProgress = 0; - // item.IsHoming = true; - // item.IsHomingCompleted = false; - - // MachineOperator.StartMotorHoming(new MotorHomingRequest() - // { - // Code = item.TechMotor.Code - // }) - // .Subscribe((response) => - // { - - // item.HomingMaximumProgress = response.Message.MaxProgress; - // item.HomingProgress = response.Message.Progress; - - // }, () => - // { - - // item.IsHoming = false; - // item.IsHomingCompleted = true; - - // }); - //} - //else if (action == MotorActionType.HomingStopped) - //{ - // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() - // { - // Code = item.TechMotor.Code, - // }); - - // item.IsHoming = false; - //} }; } @@ -991,11 +1035,13 @@ namespace Tango.MachineStudio.Technician.ViewModels { try { + CheckMachineOperator(); await MachineOperator.SetDigitalOut(new SetDigitalOutRequest() { Port = item.TechIo.Port, Value = value }); } catch (Exception ex) { - //TODO: Show Exception. + LogManager.Log(ex, String.Format("Error executing technician set digital out command on '{0}'.", item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician set digital out command on '{0}'.", item.TechName)); } }; } @@ -1010,6 +1056,7 @@ namespace Tango.MachineStudio.Technician.ViewModels { try { + CheckMachineOperator(); await MachineOperator.SetComponentValue(new SetComponentValueRequest() { Component = (ValueComponent)item.TechController.Code, @@ -1018,11 +1065,24 @@ namespace Tango.MachineStudio.Technician.ViewModels } catch (Exception ex) { - //TODO: Show Exception. + LogManager.Log(ex, String.Format("Error executing technician set value component command on '{0}'.", item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician set value component command on '{0}'.", item.TechName)); } }; } + /// + /// Checks the machine operator. + /// + /// No machine connected. + private void CheckMachineOperator() + { + if (MachineOperator == null || MachineOperator.State != Transport.TransportComponentState.Connected) + { + throw new InvalidOperationException("No machine connected."); + } + } + #endregion #region Public Methods -- cgit v1.3.1