diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-04-15 19:51:07 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-04-15 19:51:07 +0300 |
| commit | ca293b80c52a54c73251fbf3cd50741fb5653ae9 (patch) | |
| tree | f1168fa167a26bf8455e601291b8a19945a70187 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs | |
| parent | 9ff8293b603f72c5faa8d238b3005524c31cc5a8 (diff) | |
| download | Tango-ca293b80c52a54c73251fbf3cd50741fb5653ae9.tar.gz Tango-ca293b80c52a54c73251fbf3cd50741fb5653ae9.zip | |
Lots Of Work !
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs | 392 |
1 files changed, 226 insertions, 166 deletions
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 /// </summary> /// <param name="applicationManager">The application manager.</param> /// <param name="notificationProvider">The notification provider.</param> - 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<SingleGraphItem, GraphController>(); _multiControllers = new Dictionary<MultiGraphItem, GraphMultiController>(); 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<ControllerElementEditor>(item); + var editor = CreateElement<ControllerElementEditor>(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; + + MachineOperator.StartMotorHoming(new MotorHomingRequest() + { + Code = item.TechMotor.Code + }) + .Subscribe((response) => + { - item.HomingMaximumProgress = response.MaxProgress; - item.HomingProgress = response.Progress; + 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) { - Code = motor.Code, - Direction = MotorDirection.Backward, - }))); - } - else if (action == MotorActionType.BackwardReleased) - { - 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.Backward, + }))); + } + else if (action == MotorActionType.BackwardReleased) { - Code = motor.Code, - }))); - } - //else if (action == MotorActionType.HomingStarted) - //{ - // item.HomingProgress = 0; - // item.IsHoming = true; - // item.IsHomingCompleted = false; + 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) => - // { + // MachineOperator.StartMotorHoming(new MotorHomingRequest() + // { + // Code = item.TechMotor.Code + // }) + // .Subscribe((response) => + // { - // item.HomingMaximumProgress = response.Message.MaxProgress; - // item.HomingProgress = response.Message.Progress; + // item.HomingMaximumProgress = response.Message.MaxProgress; + // item.HomingProgress = response.Message.Progress; - // }, () => - // { + // }, () => + // { - // item.IsHoming = false; - // item.IsHomingCompleted = true; + // item.IsHoming = false; + // item.IsHomingCompleted = true; - // }); - //} - //else if (action == MotorActionType.HomingStopped) - //{ - // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() - // { - // Code = item.TechMotor.Code, - // }); + // }); + //} + //else if (action == MotorActionType.HomingStopped) + //{ + // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + // { + // Code = item.TechMotor.Code, + // }); - // item.IsHoming = false; - //} + // item.IsHoming = false; + //} + } + catch (Exception ex) + { + 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)); + } }; } @@ -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)); } }; } + /// <summary> + /// Checks the machine operator. + /// </summary> + /// <exception cref="InvalidOperationException">No machine connected.</exception> + private void CheckMachineOperator() + { + if (MachineOperator == null || MachineOperator.State != Transport.TransportComponentState.Connected) + { + throw new InvalidOperationException("No machine connected."); + } + } + #endregion #region Public Methods |
